Removed pthread from Zookeeper test helper. Review: https://reviews.apache.org/r/36676
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/42257809 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/42257809 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/42257809 Branch: refs/heads/master Commit: 42257809b5cee7d9c0e1b660f63a7cad0413d9ac Parents: 4fc8089 Author: Joris Van Remoortere <[email protected]> Authored: Fri Jul 24 14:36:06 2015 -0700 Committer: Benjamin Hindman <[email protected]> Committed: Fri Jul 24 15:29:04 2015 -0700 ---------------------------------------------------------------------- src/tests/zookeeper.cpp | 22 ++-------------------- src/tests/zookeeper.hpp | 10 ++++++---- 2 files changed, 8 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/42257809/src/tests/zookeeper.cpp ---------------------------------------------------------------------- diff --git a/src/tests/zookeeper.cpp b/src/tests/zookeeper.cpp index 5012017..6ce008f 100644 --- a/src/tests/zookeeper.cpp +++ b/src/tests/zookeeper.cpp @@ -96,24 +96,6 @@ void ZooKeeperTest::SetUp() } -ZooKeeperTest::TestWatcher::TestWatcher() -{ - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); - pthread_mutex_init(&mutex, &attr); - pthread_mutexattr_destroy(&attr); - pthread_cond_init(&cond, 0); -} - - -ZooKeeperTest::TestWatcher::~TestWatcher() -{ - pthread_mutex_destroy(&mutex); - pthread_cond_destroy(&cond); -} - - void ZooKeeperTest::TestWatcher::process( int type, int state, @@ -122,7 +104,7 @@ void ZooKeeperTest::TestWatcher::process( { synchronized (mutex) { events.push(Event(type, state, path)); - pthread_cond_signal(&cond); + cond.notify_one(); } } @@ -161,7 +143,7 @@ ZooKeeperTest::TestWatcher::awaitEvent() synchronized (mutex) { while (true) { while (events.empty()) { - pthread_cond_wait(&cond, &mutex); + synchronized_wait(&cond, &mutex); } Event event = events.front(); events.pop(); http://git-wip-us.apache.org/repos/asf/mesos/blob/42257809/src/tests/zookeeper.hpp ---------------------------------------------------------------------- diff --git a/src/tests/zookeeper.hpp b/src/tests/zookeeper.hpp index 32fc83b..ed34112 100644 --- a/src/tests/zookeeper.hpp +++ b/src/tests/zookeeper.hpp @@ -23,6 +23,8 @@ #include <gtest/gtest.h> +#include <condition_variable> +#include <mutex> #include <queue> #include <stout/duration.hpp> @@ -86,8 +88,8 @@ public: const std::string path; }; - TestWatcher(); - virtual ~TestWatcher(); + TestWatcher() = default; + virtual ~TestWatcher() = default; virtual void process( int type, @@ -109,8 +111,8 @@ public: private: std::queue<Event> events; - pthread_mutex_t mutex; - pthread_cond_t cond; + std::mutex mutex; + std::condition_variable cond; }; static void SetUpTestCase();
