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 cc024a1..7b4714d 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 <stdio.h>
+#ifndef _WIN32
#include <inttypes.h>
+#else
+#include <stdint.h>
+#endif
#include <limits.h>
#include "main.h"
#include "globals.h"
diff --git a/configure.ac b/configure.ac
index 2dfe95c..82ca641 100644
--- a/configure.ac
+++ b/configure.ac
@@ -445,6 +445,7 @@
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 f48aed2..a61d70f 100644
--- a/lib/cpp/Makefile.am
+++ b/lib/cpp/Makefile.am
@@ -27,7 +27,7 @@
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 @@
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 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()) {}
diff --git a/lib/cpp/src/transport/TSSLSocket.cpp b/lib/cpp/src/transport/TSSLSocket.cpp
index 7865be0..522d293 100755
--- a/lib/cpp/src/transport/TSSLSocket.cpp
+++ b/lib/cpp/src/transport/TSSLSocket.cpp
@@ -84,15 +84,15 @@
}
// TSSLSocket implementation
-TSSLSocket::TSSLSocket(shared_ptr<SSLContext> ctx):
+TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx):
TSocket(), server_(false), ssl_(NULL), ctx_(ctx) {
}
-TSSLSocket::TSSLSocket(shared_ptr<SSLContext> ctx, int socket):
+TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx, int socket):
TSocket(socket), server_(false), ssl_(NULL), ctx_(ctx) {
}
-TSSLSocket::TSSLSocket(shared_ptr<SSLContext> ctx, string host, int port):
+TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx, string host, int port):
TSocket(host, port), server_(false), ssl_(NULL), ctx_(ctx) {
}
@@ -357,7 +357,7 @@
randomize();
}
count_++;
- ctx_ = shared_ptr<SSLContext>(new SSLContext);
+ ctx_ = boost::shared_ptr<SSLContext>(new SSLContext);
}
TSSLSocketFactory::~TSSLSocketFactory() {
@@ -368,29 +368,29 @@
}
}
-shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket() {
- shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_));
+boost::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket() {
+ boost::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_));
setup(ssl);
return ssl;
}
-shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(int socket) {
- shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, socket));
+boost::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(int socket) {
+ boost::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, socket));
setup(ssl);
return ssl;
}
-shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(const string& host,
+boost::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(const string& host,
int port) {
- shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, host, port));
+ boost::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, host, port));
setup(ssl);
return ssl;
}
-void TSSLSocketFactory::setup(shared_ptr<TSSLSocket> ssl) {
+void TSSLSocketFactory::setup(boost::shared_ptr<TSSLSocket> ssl) {
ssl->server(server());
if (access_ == NULL && !server()) {
- access_ = shared_ptr<AccessManager>(new DefaultClientAccessManager);
+ access_ = boost::shared_ptr<AccessManager>(new DefaultClientAccessManager);
}
if (access_ != NULL) {
ssl->access(access_);
diff --git a/lib/cpp/test/Makefile.am b/lib/cpp/test/Makefile.am
index 6391a87..0c6d265 100644
--- a/lib/cpp/test/Makefile.am
+++ b/lib/cpp/test/Makefile.am
@@ -68,7 +68,6 @@
TBufferBaseTest.cpp
UnitTests_LDADD = \
- $(BOOST_LDFLAGS) \
libtestgencpp.la \
$(BOOST_ROOT_PATH)/lib/libboost_unit_test_framework.a
@@ -181,6 +180,7 @@
-I$(top_srcdir)/lib/cpp/src
AM_CPPFLAGS = $(BOOST_CPPFLAGS)
+AM_LDFLAGS = $(BOOST_LDFLAGS)
AM_CXXFLAGS = -Wall
clean-local: