From 0dab3832c719f7f4e87d87ab098ca967adfa807d Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Tue, 18 Oct 2011 22:19:30 +0000 Subject: [PATCH] THRIFT-1361 Optional replacement of pthread by boost::thread Patch: Alexandre Parenteau Remark: lib/cpp/src/concurrency/BoostMutex.cpp is unmodified git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1185904 13f79535-47bb-0310-9956-ffa450edef68 --- .gitignore | 1 + lib/cpp/libthrift.vcxproj | 8 +++---- lib/cpp/libthriftnb.vcxproj | 8 +++---- lib/cpp/src/concurrency/BoostMonitor.cpp | 29 ++++++++++-------------- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 02d66d93..ccce2c3b 100644 --- a/.gitignore +++ b/.gitignore @@ -87,6 +87,7 @@ /lib/erl/.generated /lib/erl/.eunit /lib/erl/ebin +/lib/erl/deps/ /lib/erl/src/thrift.app.src /lib/erl/test/*.erl /lib/erl/test/*.hrl diff --git a/lib/cpp/libthrift.vcxproj b/lib/cpp/libthrift.vcxproj index 19747fcd..a94dc3b0 100644 --- a/lib/cpp/libthrift.vcxproj +++ b/lib/cpp/libthrift.vcxproj @@ -248,16 +248,16 @@ - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(ProjectDir)\src\transport\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\openssl\OpenSSL-Win32\include\;$(IncludePath) diff --git a/lib/cpp/libthriftnb.vcxproj b/lib/cpp/libthriftnb.vcxproj index 40aa9db9..bd8ffb2d 100644 --- a/lib/cpp/libthriftnb.vcxproj +++ b/lib/cpp/libthriftnb.vcxproj @@ -100,16 +100,16 @@ - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) - $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\pthreads\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(THIRD_PARTY)\boost\boost_1_47_0\include;$(THIRD_PARTY)\boost\boost_1_47_0\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\WIN32-Code\;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\include;$(THIRD_PARTY)\libevent\libevent-2.0.13-stable\;$(IncludePath) diff --git a/lib/cpp/src/concurrency/BoostMonitor.cpp b/lib/cpp/src/concurrency/BoostMonitor.cpp index 7a9b589b..da3f281a 100644 --- a/lib/cpp/src/concurrency/BoostMonitor.cpp +++ b/lib/cpp/src/concurrency/BoostMonitor.cpp @@ -30,20 +30,15 @@ #include #include #include -#include -#include -#include 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 { public: @@ -96,11 +91,11 @@ class Monitor::Impl : public interprocess_condition { } assert(mutex_); - interprocess_mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + boost::mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); - scoped_lock lock(*mutexImpl, accept_ownership_type()); + boost::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 @@ class Monitor::Impl : public interprocess_condition { */ int waitForTime(const timespec* abstime) { assert(mutex_); - interprocess_mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + boost::mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); struct timespec currenttime; @@ -126,7 +121,7 @@ class Monitor::Impl : public interprocess_condition { if(tv_nsec < 0) tv_nsec = 0; - scoped_lock lock(*mutexImpl, accept_ownership_type()); + boost::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 @@ class Monitor::Impl : public interprocess_condition { */ int waitForever() { assert(mutex_); - interprocess_mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + boost::mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); - scoped_lock lock(*mutexImpl, accept_ownership_type()); - ((interprocess_condition*)this)->wait(lock); + boost::mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock); + ((boost::condition_variable*)this)->wait(lock); lock.release(); return 0; } -- 2.17.1