You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/12/02 17:57:01 UTC

[07/14] git commit: Rewrote ZooKeeper watcher initialization using process::Once.

Rewrote ZooKeeper watcher initialization using process::Once.

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15850


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

Branch: refs/heads/master
Commit: e94ec75b5fe2704689609c8388b7e87efaff7510
Parents: 92bbaf8
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:59:37 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:59:37 2013 -0800

----------------------------------------------------------------------
 src/zookeeper/zookeeper.cpp | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e94ec75b/src/zookeeper/zookeeper.cpp
----------------------------------------------------------------------
diff --git a/src/zookeeper/zookeeper.cpp b/src/zookeeper/zookeeper.cpp
index ca4a61d..cc8a7ca 100644
--- a/src/zookeeper/zookeeper.cpp
+++ b/src/zookeeper/zookeeper.cpp
@@ -24,6 +24,7 @@
 #include <boost/tuple/tuple.hpp>
 
 #include <process/dispatch.hpp>
+#include <process/once.hpp>
 #include <process/process.hpp>
 
 #include <stout/duration.hpp>
@@ -129,20 +130,15 @@ private:
 Watcher::Watcher()
 {
   // Confirm we have created the WatcherProcessManager.
-  static volatile bool initialized = false;
-  static volatile bool initializing = true;
+  static process::Once* initialize = new process::Once();
 
   // Confirm everything is initialized.
-  if (!initialized) {
-    if (__sync_bool_compare_and_swap(&initialized, false, true)) {
-      manager = new WatcherProcessManager();
-      process::spawn(manager);
-      initializing = false;
-    }
+  if (!initialize->once()) {
+    manager = new WatcherProcessManager();
+    process::spawn(manager);
+    initialize->done();
   }
 
-  while (initializing);
-
   WatcherProcess* process =
     process::dispatch(manager->self(),
                       &WatcherProcessManager::create,