You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2011/10/19 11:27:02 UTC

svn commit: r1186049 - /thrift/trunk/lib/cpp/src/concurrency/BoostMonitor.cpp

Author: roger
Date: Wed Oct 19 09:27:01 2011
New Revision: 1186049

URL: http://svn.apache.org/viewvc?rev=1186049&view=rev
Log:
THRIFT-1361 Optional replacement of pthread by boost::thread
revert boost changes

Modified:
    thrift/trunk/lib/cpp/src/concurrency/BoostMonitor.cpp

Modified: thrift/trunk/lib/cpp/src/concurrency/BoostMonitor.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/concurrency/BoostMonitor.cpp?rev=1186049&r1=1186048&r2=1186049&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/concurrency/BoostMonitor.cpp (original)
+++ thrift/trunk/lib/cpp/src/concurrency/BoostMonitor.cpp Wed Oct 19 09:27:01 2011
@@ -30,15 +30,20 @@
 #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 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::cond
     }
 
     assert(mutex_);
-	boost::mutex* mutexImpl =
-      reinterpret_cast<boost::mutex*>(mutex_->getUnderlyingImpl());
+    interprocess_mutex* mutexImpl =
+      reinterpret_cast<interprocess_mutex*>(mutex_->getUnderlyingImpl());
     assert(mutexImpl);
 
-	boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
+	scoped_lock<interprocess_mutex> 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::cond
    */
   int waitForTime(const timespec* abstime) {
     assert(mutex_);
-    boost::mutex* mutexImpl =
-      reinterpret_cast<boost::mutex*>(mutex_->getUnderlyingImpl());
+    interprocess_mutex* mutexImpl =
+      reinterpret_cast<interprocess_mutex*>(mutex_->getUnderlyingImpl());
     assert(mutexImpl);
 
     struct timespec currenttime;
@@ -121,7 +126,7 @@ class Monitor::Impl : public boost::cond
 	if(tv_nsec < 0)
 		tv_nsec = 0;
 
-	boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
+	scoped_lock<interprocess_mutex> 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::cond
    */
   int waitForever() {
     assert(mutex_);
-    boost::mutex* mutexImpl =
-      reinterpret_cast<boost::mutex*>(mutex_->getUnderlyingImpl());
+    interprocess_mutex* mutexImpl =
+      reinterpret_cast<interprocess_mutex*>(mutex_->getUnderlyingImpl());
     assert(mutexImpl);
 
-	boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
-	((boost::condition_variable*)this)->wait(lock);
+	scoped_lock<interprocess_mutex> lock(*mutexImpl, accept_ownership_type());
+	((interprocess_condition*)this)->wait(lock);
 	lock.release();
     return 0;
   }