You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/11/23 20:39:04 UTC

[1/3] mesos git commit: Libprocess: Removed some undocumented, commented-out code.

Repository: mesos
Updated Branches:
  refs/heads/master 2db1e7268 -> 800860578


Libprocess: Removed some undocumented, commented-out code.

These are remnants of commented-out code, dating back to when
libprocess was originally open-sourced.

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


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

Branch: refs/heads/master
Commit: b094f65758c86244793cda904fb6732db29e3f1b
Parents: 2db1e72
Author: Joseph Wu <jo...@mesosphere.io>
Authored: Mon Nov 23 13:43:21 2015 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 23 14:10:58 2015 -0500

----------------------------------------------------------------------
 3rdparty/libprocess/src/process.cpp | 40 --------------------------------
 1 file changed, 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b094f657/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index b89e14a..e4ada4a 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -733,9 +733,6 @@ void initialize(const string& delegate)
   // TODO(benh): Return an error if attempting to initialize again
   // with a different delegate than originally specified.
 
-  // static pthread_once_t init = PTHREAD_ONCE_INIT;
-  // pthread_once(&init, ...);
-
   static std::atomic_bool initialized(false);
   static std::atomic_bool initializing(true);
 
@@ -755,28 +752,6 @@ void initialize(const string& delegate)
     }
   }
 
-//   // Install signal handler.
-//   struct sigaction sa;
-
-//   sa.sa_handler = (void (*) (int)) sigbad;
-//   sigemptyset (&sa.sa_mask);
-//   sa.sa_flags = SA_RESTART;
-
-//   sigaction (SIGTERM, &sa, NULL);
-//   sigaction (SIGINT, &sa, NULL);
-//   sigaction (SIGQUIT, &sa, NULL);
-//   sigaction (SIGSEGV, &sa, NULL);
-//   sigaction (SIGILL, &sa, NULL);
-// #ifdef SIGBUS
-//   sigaction (SIGBUS, &sa, NULL);
-// #endif
-// #ifdef SIGSTKFLT
-//   sigaction (SIGSTKFLT, &sa, NULL);
-// #endif
-//   sigaction (SIGABRT, &sa, NULL);
-
-//   sigaction (SIGFPE, &sa, NULL);
-
 #ifdef __sun__
   /* Need to ignore this since we can't do MSG_NOSIGNAL on Solaris. */
   signal(SIGPIPE, SIG_IGN);
@@ -803,21 +778,6 @@ void initialize(const string& delegate)
 
   Clock::initialize(lambda::bind(&timedout, lambda::_1));
 
-//   ev_child_init(&child_watcher, child_exited, pid, 0);
-//   ev_child_start(loop, &cw);
-
-//   /* Install signal handler. */
-//   struct sigaction sa;
-
-//   sa.sa_handler = ev_sighandler;
-//   sigfillset (&sa.sa_mask);
-//   sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
-//   sigaction (w->signum, &sa, 0);
-
-//   sigemptyset (&sa.sa_mask);
-//   sigaddset (&sa.sa_mask, w->signum);
-//   sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
-
   __address__ = Address::LOCALHOST_ANY();
 
   // Check environment for ip.


[3/3] mesos git commit: Libprocess `Once`: removed unused includes.

Posted by jo...@apache.org.
Libprocess `Once`: removed unused includes.


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

Branch: refs/heads/master
Commit: 80086057883137d74a8289d4d07961cd44fee30d
Parents: 0e56a04
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Mon Nov 23 14:09:24 2015 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 23 14:32:29 2015 -0500

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/once.hpp | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/80086057/3rdparty/libprocess/include/process/once.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/once.hpp b/3rdparty/libprocess/include/process/once.hpp
index 975fc95..d5febb4 100644
--- a/3rdparty/libprocess/include/process/once.hpp
+++ b/3rdparty/libprocess/include/process/once.hpp
@@ -16,9 +16,6 @@
 #include <condition_variable>
 #include <mutex>
 
-#include <process/future.hpp>
-
-#include <stout/nothing.hpp>
 #include <stout/synchronized.hpp>
 
 namespace process {


[2/3] mesos git commit: Documented and simplified libprocess initialization.

Posted by jo...@apache.org.
Documented and simplified libprocess initialization.

* Renamed `initialized` to `initialize_started`.
* Renamed `initializing` to `initialize_complete`.
* Removed the (2) condition, described below:

The initialization synchronization logic contains three conditions,
which check:
1) Was `initialize` called and is it done?
2) Was `initialize` called and is it not done?
3) Are you the first to call `initialize`?

Condition (3) uses `compare_exchange_strong` between `initialized` and
`false`.  This returns `true` (and sets `initialized` to true) iff the
caller is the first to reach that expression.

The second simultaneous caller of `initialize` will either satisify
condition (2) or (3) and then wait on `initializing`.  For the second
caller, (2) and (3) are identical because `compare_exchange_strong`
between `true` and `false` will always return false, thereby putting
the second caller into the waiting loop.

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


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

Branch: refs/heads/master
Commit: 0e56a04d0ebdfa623455c03dd737ceb2c49cd57b
Parents: b094f65
Author: Joseph Wu <jo...@mesosphere.io>
Authored: Mon Nov 23 13:50:16 2015 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 23 14:15:31 2015 -0500

----------------------------------------------------------------------
 3rdparty/libprocess/src/process.cpp | 43 ++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0e56a04d/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index e4ada4a..0fa15dd 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -733,21 +733,38 @@ void initialize(const string& delegate)
   // TODO(benh): Return an error if attempting to initialize again
   // with a different delegate than originally specified.
 
-  static std::atomic_bool initialized(false);
-  static std::atomic_bool initializing(true);
+  // NOTE: Rather than calling `initialize` once at the root of the
+  // dependency tree; we currently rely on libprocess dependency
+  // declaration by invoking `initialize` prior to use. This is done
+  // frequently throughout the code base. Therefore we chose to use
+  // atomics rather than `Once`, as the overhead of a mutex and
+  // condition variable is exessive here.
+  static std::atomic_bool initialize_started(false);
+  static std::atomic_bool initialize_complete(false);
 
   // Try and do the initialization or wait for it to complete.
-  // TODO(neilc): Try to simplify and/or document this logic.
-  if (initialized.load() && !initializing.load()) {
-    return;
-  } else if (initialized.load() && initializing.load()) {
-    while (initializing.load());
+
+  // If already initialized, there's nothing more to do.
+  // NOTE: This condition is true as soon as the thread performing
+  // initialization sets `initialize_complete` to `true` in the *middle*
+  // of initialization.  This is done because some methods called by
+  // initialization will themselves call `process::initialize`.
+  if (initialize_started.load() && initialize_complete.load()) {
     return;
+
   } else {
-    // `compare_exchange_strong` needs an lvalue.
+    // NOTE: `compare_exchange_strong` needs an lvalue.
     bool expected = false;
-    if (!initialized.compare_exchange_strong(expected, true)) {
-      while (initializing.load());
+
+    // Any thread that calls `initialize` prior to when `initialize_complete`
+    // is set to `true` will reach this.
+
+    // Atomically sets `initialize_started` to `true`.  The thread that
+    // successfully sets `initialize_started` to `true` will move on to
+    // perform the initialization logic.  All others will wait here for
+    // initialization to complete.
+    if (!initialize_started.compare_exchange_strong(expected, true)) {
+      while (!initialize_complete.load());
       return;
     }
   }
@@ -873,9 +890,9 @@ void initialize(const string& delegate)
     PLOG(FATAL) << "Failed to initialize: " << listen.error();
   }
 
-  // Need to set `initializing` here so that we can actually invoke `spawn()`
-  // below for the garbage collector.
-  initializing.store(false);
+  // Need to set `initialize_complete` here so that we can actually
+  // invoke `accept()` and `spawn()` below.
+  initialize_complete.store(true);
 
   __s__->accept()
     .onAny(lambda::bind(&internal::on_accept, lambda::_1));