From 266a6b5c113538ba95a21e6b308389c9d59c6762 Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Wed, 19 Oct 2011 09:27:01 +0000 Subject: [PATCH] THRIFT-1361 Optional replacement of pthread by boost::thread revert boost changes git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1186049 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/concurrency/BoostMonitor.cpp | 29 ++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/cpp/src/concurrency/BoostMonitor.cpp b/lib/cpp/src/concurrency/BoostMonitor.cpp index da3f281a..7a9b589b 100644 --- a/lib/cpp/src/concurrency/BoostMonitor.cpp +++ b/lib/cpp/src/concurrency/BoostMonitor.cpp @@ -30,15 +30,20 @@ #include #include #include +#include +#include +#include namespace apache { namespace thrift { namespace concurrency { +using namespace boost::interprocess; + /** - * Monitor implementation using the boost thread library + * Monitor implementation using the boost interprocess library * * @version $Id:$ */ -class Monitor::Impl : public boost::condition_variable { +class Monitor::Impl : public interprocess_condition { public: @@ -91,11 +96,11 @@ class Monitor::Impl : public boost::condition_variable { } assert(mutex_); - boost::mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + interprocess_mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); - boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock); + scoped_lock lock(*mutexImpl, accept_ownership_type()); int res = timed_wait(lock, boost::get_system_time()+boost::posix_time::milliseconds(timeout_ms)) ? 0 : ETIMEDOUT; lock.release(); return res; @@ -107,8 +112,8 @@ class Monitor::Impl : public boost::condition_variable { */ int waitForTime(const timespec* abstime) { assert(mutex_); - boost::mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + interprocess_mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); struct timespec currenttime; @@ -121,7 +126,7 @@ class Monitor::Impl : public boost::condition_variable { if(tv_nsec < 0) tv_nsec = 0; - boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock); + scoped_lock lock(*mutexImpl, accept_ownership_type()); int res = timed_wait(lock, boost::get_system_time() + boost::posix_time::seconds(tv_sec) + boost::posix_time::microseconds(tv_nsec / 1000) @@ -136,12 +141,12 @@ class Monitor::Impl : public boost::condition_variable { */ int waitForever() { assert(mutex_); - boost::mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + interprocess_mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); - boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock); - ((boost::condition_variable*)this)->wait(lock); + scoped_lock lock(*mutexImpl, accept_ownership_type()); + ((interprocess_condition*)this)->wait(lock); lock.release(); return 0; } -- 2.17.1