From: Roger Meier Date: Sun, 6 Nov 2011 11:29:41 +0000 (+0000) Subject: THRIFT-1361 Optional replacement of pthread by boost::thread X-Git-Tag: 0.8.0~28 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=38315786e5c9e972aef50433b401dcff23259cae;p=common%2Fthrift.git 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/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index cc024a1a..7b4714d9 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -28,7 +28,11 @@ #define __STDC_LIMIT_MACROS #define __STDC_FORMAT_MACROS #include +#ifndef _WIN32 #include +#else +#include +#endif #include #include "main.h" #include "globals.h" diff --git a/configure.ac b/configure.ac index 2dfe95c1..82ca641a 100644 --- a/configure.ac +++ b/configure.ac @@ -445,6 +445,7 @@ AC_ARG_ENABLE(boostthreads, if test "x[$]ENABLE_BOOSTTHREADS" = "x1"; then AC_MSG_WARN(enable boostthreads) AC_DEFINE([USE_BOOST_THREAD], [1], [experimental --enable-boostthreads that replaces POSIX pthread by boost::thread]) + LIBS="-lboost_thread $LIBS" fi AM_CONDITIONAL([WITH_BOOSTTHREADS], [test "x[$]ENABLE_BOOSTTHREADS" = "x1"]) diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am index f48aed2a..a61d70f2 100644 --- a/lib/cpp/Makefile.am +++ b/lib/cpp/Makefile.am @@ -27,7 +27,7 @@ pkgconfigdir = $(libdir)/pkgconfig lib_LTLIBRARIES = libthrift.la pkgconfig_DATA = thrift.pc -libthrift_la_LDFLAGS = -release $(VERSION) +libthrift_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) ## We only build the extra libraries if we have the dependencies, ## but we install all of the headers unconditionally. @@ -100,12 +100,8 @@ libthriftnb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBEVENT_CPPFLAGS) libthriftz_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS) libthriftnb_la_CXXFLAGS = $(AM_CXXFLAGS) libthriftz_la_CXXFLAGS = $(AM_CXXFLAGS) -libthriftnb_la_LDFLAGS = -release $(VERSION) -libthriftz_la_LDFLAGS = -release $(VERSION) - -if WITH_BOOSTTHREADS -libthrift_la_LIBADD = -lboost_thread -endif +libthriftnb_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) +libthriftz_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) include_thriftdir = $(includedir)/thrift include_thrift_HEADERS = \ diff --git a/lib/cpp/src/concurrency/BoostMonitor.cpp b/lib/cpp/src/concurrency/BoostMonitor.cpp index 7a9b589b..2adf7d73 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_any { public: @@ -96,11 +91,11 @@ class Monitor::Impl : public interprocess_condition { } assert(mutex_); - interprocess_mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + boost::timed_mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); - scoped_lock 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 @@ class Monitor::Impl : public interprocess_condition { */ int waitForTime(const timespec* abstime) { assert(mutex_); - interprocess_mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + boost::timed_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::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 @@ class Monitor::Impl : public interprocess_condition { */ int waitForever() { assert(mutex_); - interprocess_mutex* mutexImpl = - reinterpret_cast(mutex_->getUnderlyingImpl()); + boost::timed_mutex* mutexImpl = + reinterpret_cast(mutex_->getUnderlyingImpl()); assert(mutexImpl); - scoped_lock 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 2277f615..a7b5c377 100644 --- a/lib/cpp/src/concurrency/BoostMutex.cpp +++ b/lib/cpp/src/concurrency/BoostMutex.cpp @@ -25,10 +25,8 @@ #include #include +#include #include -#include - -using namespace boost::interprocess; namespace apache { namespace thrift { namespace concurrency { @@ -37,7 +35,7 @@ namespace apache { namespace thrift { namespace concurrency { * * @version $Id:$ */ -class Mutex::impl : public interprocess_mutex { +class Mutex::impl : public boost::timed_mutex { }; Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {} diff --git a/lib/cpp/src/transport/TSSLSocket.cpp b/lib/cpp/src/transport/TSSLSocket.cpp index 7865be04..522d293f 100755 --- a/lib/cpp/src/transport/TSSLSocket.cpp +++ b/lib/cpp/src/transport/TSSLSocket.cpp @@ -84,15 +84,15 @@ SSL* SSLContext::createSSL() { } // TSSLSocket implementation -TSSLSocket::TSSLSocket(shared_ptr ctx): +TSSLSocket::TSSLSocket(boost::shared_ptr ctx): TSocket(), server_(false), ssl_(NULL), ctx_(ctx) { } -TSSLSocket::TSSLSocket(shared_ptr ctx, int socket): +TSSLSocket::TSSLSocket(boost::shared_ptr ctx, int socket): TSocket(socket), server_(false), ssl_(NULL), ctx_(ctx) { } -TSSLSocket::TSSLSocket(shared_ptr ctx, string host, int port): +TSSLSocket::TSSLSocket(boost::shared_ptr ctx, string host, int port): TSocket(host, port), server_(false), ssl_(NULL), ctx_(ctx) { } @@ -357,7 +357,7 @@ TSSLSocketFactory::TSSLSocketFactory(): server_(false) { randomize(); } count_++; - ctx_ = shared_ptr(new SSLContext); + ctx_ = boost::shared_ptr(new SSLContext); } TSSLSocketFactory::~TSSLSocketFactory() { @@ -368,29 +368,29 @@ TSSLSocketFactory::~TSSLSocketFactory() { } } -shared_ptr TSSLSocketFactory::createSocket() { - shared_ptr ssl(new TSSLSocket(ctx_)); +boost::shared_ptr TSSLSocketFactory::createSocket() { + boost::shared_ptr ssl(new TSSLSocket(ctx_)); setup(ssl); return ssl; } -shared_ptr TSSLSocketFactory::createSocket(int socket) { - shared_ptr ssl(new TSSLSocket(ctx_, socket)); +boost::shared_ptr TSSLSocketFactory::createSocket(int socket) { + boost::shared_ptr ssl(new TSSLSocket(ctx_, socket)); setup(ssl); return ssl; } -shared_ptr TSSLSocketFactory::createSocket(const string& host, +boost::shared_ptr TSSLSocketFactory::createSocket(const string& host, int port) { - shared_ptr ssl(new TSSLSocket(ctx_, host, port)); + boost::shared_ptr ssl(new TSSLSocket(ctx_, host, port)); setup(ssl); return ssl; } -void TSSLSocketFactory::setup(shared_ptr ssl) { +void TSSLSocketFactory::setup(boost::shared_ptr ssl) { ssl->server(server()); if (access_ == NULL && !server()) { - access_ = shared_ptr(new DefaultClientAccessManager); + access_ = boost::shared_ptr(new DefaultClientAccessManager); } if (access_ != NULL) { ssl->access(access_); diff --git a/lib/cpp/test/Makefile.am b/lib/cpp/test/Makefile.am index 6391a879..0c6d2654 100644 --- a/lib/cpp/test/Makefile.am +++ b/lib/cpp/test/Makefile.am @@ -68,7 +68,6 @@ UnitTests_SOURCES = \ TBufferBaseTest.cpp UnitTests_LDADD = \ - $(BOOST_LDFLAGS) \ libtestgencpp.la \ $(BOOST_ROOT_PATH)/lib/libboost_unit_test_framework.a @@ -181,6 +180,7 @@ INCLUDES = \ -I$(top_srcdir)/lib/cpp/src AM_CPPFLAGS = $(BOOST_CPPFLAGS) +AM_LDFLAGS = $(BOOST_LDFLAGS) AM_CXXFLAGS = -Wall clean-local: