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/09/11 04:40:02 UTC
[2/4] mesos git commit: stout: Replace GCC intrinsics with
std::atomic.
stout: Replace GCC intrinsics with std::atomic.
MESOS-3326.
Review: https://reviews.apache.org/r/37876
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4a01850c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4a01850c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4a01850c
Branch: refs/heads/master
Commit: 4a01850c554048cfa53ca03d7d6e3cf901ce166d
Parents: 9411749
Author: Neil Conway <ne...@gmail.com>
Authored: Thu Sep 10 17:50:13 2015 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Sep 10 19:39:41 2015 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/os/posix/fork.hpp | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4a01850c/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
index d43433a..7eb51e8 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/fork.hpp
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <sys/wait.h>
+#include <atomic>
#include <list>
#include <memory>
#include <set>
@@ -232,7 +233,7 @@ private:
pid_t group;
pid_t session;
- bool set; // Has this been initialized?
+ std::atomic_bool set; // Has this been initialized?
};
std::shared_ptr<Memory> memory;
@@ -274,11 +275,11 @@ private:
// Constructs a Tree (see above) from this fork template.
Try<Tree> prepare() const
{
- static int forks = 0;
+ static std::atomic_int forks(0);
// Each "instance" of an instantiated Fork needs a unique name for
// creating shared memory.
- int instance = __sync_fetch_and_add(&forks, 1);
+ int instance = forks.fetch_add(1);
std::string name =
"/stout-forks-" + stringify(getpid()) + stringify(instance);
@@ -312,7 +313,7 @@ private:
Tree tree;
tree.memory = std::shared_ptr<Tree::Memory>((Tree::Memory*)memory, deleter);
- tree.memory->set = false;
+ tree.memory->set.store(false);
for (size_t i = 0; i < children.size(); i++) {
Try<Tree> tree_ = children[i].prepare();
@@ -340,7 +341,7 @@ private:
process.parent = getppid();
process.group = getpgid(0);
process.session = getsid(0);
- process.set = true;
+ process.set.store(true);
// Copy it into shared memory.
memcpy(tree.memory.get(), &process, sizeof(Tree::Memory));
@@ -381,10 +382,7 @@ private:
{
// Wait for the forked process.
// TODO(benh): Don't wait forever?
- while (!tree.memory->set) {
- // Make sure we don't keep reading the value from a register.
- __sync_synchronize();
- }
+ while (!tree.memory->set.load());
// All processes in the returned ProcessTree will have the
// command-line of the top level process, since we construct the