THRIFT-1361 Optional replacement of pthread by boost::thread
Patch: Alexandre Parenteau
rev3
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1198339 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/BoostMonitor.cpp b/lib/cpp/src/concurrency/BoostMonitor.cpp
index 7a9b589..2adf7d7 100644
--- a/lib/cpp/src/concurrency/BoostMonitor.cpp
+++ b/lib/cpp/src/concurrency/BoostMonitor.cpp
@@ -30,20 +30,15 @@
#include <boost/scoped_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/interprocess/sync/interprocess_mutex.hpp>
-#include <boost/interprocess/sync/interprocess_condition.hpp>
-#include <boost/interprocess/sync/scoped_lock.hpp>
namespace apache { namespace thrift { namespace concurrency {
-using namespace boost::interprocess;
-
/**
- * Monitor implementation using the boost interprocess library
+ * Monitor implementation using the boost thread library
*
* @version $Id:$
*/
-class Monitor::Impl : public interprocess_condition {
+class Monitor::Impl : public boost::condition_variable_any {
public:
@@ -96,11 +91,11 @@
}
assert(mutex_);
- interprocess_mutex* mutexImpl =
- reinterpret_cast<interprocess_mutex*>(mutex_->getUnderlyingImpl());
+ boost::timed_mutex* mutexImpl =
+ reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
assert(mutexImpl);
- scoped_lock<interprocess_mutex> lock(*mutexImpl, accept_ownership_type());
+ boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
int res = timed_wait(lock, boost::get_system_time()+boost::posix_time::milliseconds(timeout_ms)) ? 0 : ETIMEDOUT;
lock.release();
return res;
@@ -112,8 +107,8 @@
*/
int waitForTime(const timespec* abstime) {
assert(mutex_);
- interprocess_mutex* mutexImpl =
- reinterpret_cast<interprocess_mutex*>(mutex_->getUnderlyingImpl());
+ boost::timed_mutex* mutexImpl =
+ reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
assert(mutexImpl);
struct timespec currenttime;
@@ -126,7 +121,7 @@
if(tv_nsec < 0)
tv_nsec = 0;
- scoped_lock<interprocess_mutex> lock(*mutexImpl, accept_ownership_type());
+ boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
int res = timed_wait(lock, boost::get_system_time() +
boost::posix_time::seconds(tv_sec) +
boost::posix_time::microseconds(tv_nsec / 1000)
@@ -141,12 +136,12 @@
*/
int waitForever() {
assert(mutex_);
- interprocess_mutex* mutexImpl =
- reinterpret_cast<interprocess_mutex*>(mutex_->getUnderlyingImpl());
+ boost::timed_mutex* mutexImpl =
+ reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
assert(mutexImpl);
- scoped_lock<interprocess_mutex> lock(*mutexImpl, accept_ownership_type());
- ((interprocess_condition*)this)->wait(lock);
+ boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
+ ((boost::condition_variable_any*)this)->wait(lock);
lock.release();
return 0;
}
diff --git a/lib/cpp/src/concurrency/BoostMutex.cpp b/lib/cpp/src/concurrency/BoostMutex.cpp
index 2277f61..a7b5c37 100644
--- a/lib/cpp/src/concurrency/BoostMutex.cpp
+++ b/lib/cpp/src/concurrency/BoostMutex.cpp
@@ -25,10 +25,8 @@
#include <cassert>
#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/interprocess/sync/interprocess_mutex.hpp>
-
-using namespace boost::interprocess;
namespace apache { namespace thrift { namespace concurrency {
@@ -37,7 +35,7 @@
*
* @version $Id:$
*/
-class Mutex::impl : public interprocess_mutex {
+class Mutex::impl : public boost::timed_mutex {
};
Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {}