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 2015/07/25 00:29:19 UTC
[4/8] mesos git commit: Removed pthread from Once and Gate.
Removed pthread from Once and Gate.
Review: https://reviews.apache.org/r/36673
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1bd50fc5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1bd50fc5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1bd50fc5
Branch: refs/heads/master
Commit: 1bd50fc5c0c0825bab1195c608d9cd2c5b3f0479
Parents: 3817760
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Fri Jul 24 14:35:02 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Fri Jul 24 15:29:04 2015 -0700
----------------------------------------------------------------------
3rdparty/libprocess/include/process/once.hpp | 23 ++++++++-----------
3rdparty/libprocess/src/gate.hpp | 27 +++++++++--------------
2 files changed, 19 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/1bd50fc5/3rdparty/libprocess/include/process/once.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/once.hpp b/3rdparty/libprocess/include/process/once.hpp
index 7d0d930..4b0cbe0 100644
--- a/3rdparty/libprocess/include/process/once.hpp
+++ b/3rdparty/libprocess/include/process/once.hpp
@@ -15,6 +15,9 @@
#ifndef __PROCESS_ONCE_HPP__
#define __PROCESS_ONCE_HPP__
+#include <condition_variable>
+#include <mutex>
+
#include <process/future.hpp>
#include <stout/nothing.hpp>
@@ -27,17 +30,9 @@ namespace process {
class Once
{
public:
- Once() : started(false), finished(false)
- {
- pthread_mutex_init(&mutex, NULL);
- pthread_cond_init(&cond, NULL);
- }
+ Once() : started(false), finished(false) {}
- ~Once()
- {
- pthread_cond_destroy(&cond);
- pthread_mutex_destroy(&mutex);
- }
+ ~Once() = default;
// Returns true if this Once instance has already transitioned to a
// 'done' state (i.e., the action you wanted to perform "once" has
@@ -50,7 +45,7 @@ public:
synchronized (mutex) {
if (started) {
while (!finished) {
- pthread_cond_wait(&cond, &mutex);
+ synchronized_wait(&cond, &mutex);
}
result = true;
} else {
@@ -67,7 +62,7 @@ public:
synchronized (mutex) {
if (started && !finished) {
finished = true;
- pthread_cond_broadcast(&cond);
+ cond.notify_all();
}
}
}
@@ -77,8 +72,8 @@ private:
Once(const Once& that);
Once& operator = (const Once& that);
- pthread_mutex_t mutex;
- pthread_cond_t cond;
+ std::mutex mutex;
+ std::condition_variable cond;
bool started;
bool finished;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/1bd50fc5/3rdparty/libprocess/src/gate.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/gate.hpp b/3rdparty/libprocess/src/gate.hpp
index 7f6b3d8..7d5df70 100644
--- a/3rdparty/libprocess/src/gate.hpp
+++ b/3rdparty/libprocess/src/gate.hpp
@@ -15,7 +15,8 @@
#ifndef __GATE_HPP__
#define __GATE_HPP__
-// TODO(benh): Build implementation directly on-top-of futex's for Linux.
+#include <condition_variable>
+#include <mutex>
#include <stout/synchronized.hpp>
@@ -27,21 +28,13 @@ public:
private:
int waiters;
state_t state;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
+ std::mutex mutex;
+ std::condition_variable cond;
public:
- Gate() : waiters(0), state(0)
- {
- pthread_mutex_init(&mutex, NULL);
- pthread_cond_init(&cond, NULL);
- }
+ Gate() : waiters(0), state(0) {}
- ~Gate()
- {
- pthread_cond_destroy(&cond);
- pthread_mutex_destroy(&mutex);
- }
+ ~Gate() = default;
// Signals the state change of the gate to any (at least one) or
// all (if 'all' is true) of the threads waiting on it.
@@ -50,9 +43,9 @@ public:
synchronized (mutex) {
state++;
if (all) {
- pthread_cond_broadcast(&cond);
+ cond.notify_all();
} else {
- pthread_cond_signal(&cond);
+ cond.notify_one();
}
}
}
@@ -65,7 +58,7 @@ public:
waiters++;
state_t old = state;
while (old == state) {
- pthread_cond_wait(&cond, &mutex);
+ synchronized_wait(&cond, &mutex);
}
waiters--;
}
@@ -89,7 +82,7 @@ public:
{
synchronized (mutex) {
while (old == state) {
- pthread_cond_wait(&cond, &mutex);
+ synchronized_wait(&cond, &mutex);
}
waiters--;