Used std::thread instead of pthread for Libprocess process.

Review: https://reviews.apache.org/r/36715


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cbb20999
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cbb20999
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cbb20999

Branch: refs/heads/master
Commit: cbb2099919a0790bdbdffb8e2a7f2231f632567c
Parents: 8574d0c
Author: Joris Van Remoortere <[email protected]>
Authored: Fri Jul 24 14:51:11 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Fri Jul 24 15:29:05 2015 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/event_loop.hpp |  2 +-
 3rdparty/libprocess/src/libev.cpp      |  4 +---
 3rdparty/libprocess/src/libevent.cpp   |  4 +---
 3rdparty/libprocess/src/process.cpp    | 24 ++++++++++++------------
 4 files changed, 15 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cbb20999/3rdparty/libprocess/src/event_loop.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/event_loop.hpp 
b/3rdparty/libprocess/src/event_loop.hpp
index 45aa2a6..36a4cd2 100644
--- a/3rdparty/libprocess/src/event_loop.hpp
+++ b/3rdparty/libprocess/src/event_loop.hpp
@@ -40,7 +40,7 @@ public:
   static double time();
 
   // Runs the event loop.
-  static void* run(void*);
+  static void run();
 };
 
 } // namespace process {

http://git-wip-us.apache.org/repos/asf/mesos/blob/cbb20999/3rdparty/libprocess/src/libev.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libev.cpp 
b/3rdparty/libprocess/src/libev.cpp
index 4fa484b..5301ce0 100644
--- a/3rdparty/libprocess/src/libev.cpp
+++ b/3rdparty/libprocess/src/libev.cpp
@@ -127,15 +127,13 @@ double EventLoop::time()
 }
 
 
-void* EventLoop::run(void*)
+void EventLoop::run()
 {
   __in_event_loop__ = true;
 
   ev_loop(loop, 0);
 
   __in_event_loop__ = false;
-
-  return NULL;
 }
 
 } // namespace process {

http://git-wip-us.apache.org/repos/asf/mesos/blob/cbb20999/3rdparty/libprocess/src/libevent.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent.cpp 
b/3rdparty/libprocess/src/libevent.cpp
index 1e44f2a..6e37946 100644
--- a/3rdparty/libprocess/src/libevent.cpp
+++ b/3rdparty/libprocess/src/libevent.cpp
@@ -90,7 +90,7 @@ void run_in_event_loop(
 }
 
 
-void* EventLoop::run(void*)
+void EventLoop::run()
 {
   __in_event_loop__ = true;
 
@@ -123,8 +123,6 @@ void* EventLoop::run(void*)
       LOG(FATAL) << "Failure to unblock SIGPIPE";
     }
   }
-
-  return NULL;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/cbb20999/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp 
b/3rdparty/libprocess/src/process.cpp
index 7a5a60d..34bfe40 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -15,7 +15,6 @@
 #include <errno.h>
 #include <limits.h>
 #include <netdb.h>
-#include <pthread.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdint.h>
@@ -53,6 +52,7 @@
 #include <sstream>
 #include <stack>
 #include <stdexcept>
+#include <thread>
 #include <utility>
 #include <vector>
 
@@ -641,10 +641,8 @@ void decode_recv(
     .onAny(lambda::bind(&decode_recv, lambda::_1, data, size, socket, 
decoder));
 }
 
-} // namespace internal {
-
 
-void* schedule(void* arg)
+void schedule()
 {
   do {
     ProcessBase* process = process_manager->dequeue();
@@ -662,6 +660,8 @@ void* schedule(void* arg)
   } while (true);
 }
 
+} // namespace internal {
+
 
 void timedout(const list<Timer>& timers)
 {
@@ -820,10 +820,10 @@ void initialize(const string& delegate)
   long cpus = std::max(8L, sysconf(_SC_NPROCESSORS_ONLN));
 
   for (int i = 0; i < cpus; i++) {
-    pthread_t thread; // For now, not saving handles on our threads.
-    if (pthread_create(&thread, NULL, schedule, NULL) != 0) {
-      LOG(FATAL) << "Failed to initialize, pthread_create";
-    }
+    // We detach and forget the thread handle as we are not joining it
+    // for a clean shutdown.
+    std::thread* thread = new std::thread(&internal::schedule);
+    thread->detach();
   }
 
   // Initialize the event loop.
@@ -845,10 +845,10 @@ void initialize(const string& delegate)
 //   sigaddset (&sa.sa_mask, w->signum);
 //   sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
 
-  pthread_t thread; // For now, not saving handles on our threads.
-  if (pthread_create(&thread, NULL, &EventLoop::run, NULL) != 0) {
-    LOG(FATAL) << "Failed to initialize, pthread_create";
-  }
+  // We detach and forget the thread handle as we are not joining it
+  // for a clean shutdown.
+  std::thread* thread = new std::thread(&EventLoop::run);
+  thread->detach();
 
   __address__ = Address::LOCALHOST_ANY();
 

Reply via email to