This is an automated email from the ASF dual-hosted git repository. jking pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/thrift.git
commit c109e019790a87ef1f874dfac3482ac45a57d3ab Author: cyy <cyye...@outlook.com> AuthorDate: Sat Jan 5 13:45:07 2019 +0800 remove boost::thread and boost::mutex code --- .travis.yml | 2 +- build/cmake/DefineOptions.cmake | 7 +- build/cmake/DefinePlatformSpecifc.cmake | 4 +- build/cmake/README-MSYS2.md | 2 +- build/cmake/README.md | 2 +- build/cmake/config.h.in | 3 - build/wincpp/build-thrift.bat | 1 - configure.ac | 18 -- contrib/transport-sample/ThriftCommon.h | 2 - lib/cpp/CMakeLists.txt | 9 +- lib/cpp/Makefile.am | 7 - lib/cpp/src/thrift/concurrency/BoostMonitor.cpp | 214 --------------------- lib/cpp/src/thrift/concurrency/BoostMutex.cpp | 73 ------- .../src/thrift/concurrency/BoostThreadFactory.cpp | 162 ---------------- .../src/thrift/concurrency/BoostThreadFactory.h | 63 ------ .../src/thrift/concurrency/PlatformThreadFactory.h | 8 +- lib/cpp/src/thrift/concurrency/Thread.h | 11 +- lib/cpp/src/thrift/server/TNonblockingServer.cpp | 2 +- lib/cpp/src/thrift/windows/TWinsockSingleton.cpp | 10 - lib/cpp/src/thrift/windows/TWinsockSingleton.h | 12 -- lib/cpp/src/thrift/windows/config.h | 3 - lib/cpp/test/CMakeLists.txt | 2 +- lib/cpp/test/Makefile.am | 2 - lib/cpp/test/TNonblockingSSLServerTest.cpp | 2 +- lib/cpp/test/TNonblockingServerTest.cpp | 2 +- lib/cpp/test/concurrency/ThreadManagerTests.h | 8 +- 26 files changed, 19 insertions(+), 612 deletions(-) diff --git a/.travis.yml b/.travis.yml index e09b8a4..96e0b51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -142,7 +142,7 @@ jobs: - JOB="C++98 (Boost Thread)" - SCRIPT="cmake.sh" - BUILD_LIBS="CPP TESTING TUTORIALS" - - BUILD_ARG="-DCMAKE_CXX_STANDARD=98 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF --DWITH_BOOSTTHREADS=ON -DWITH_PYTHON=OFF -DWITH_C_GLIB=OFF -DWITH_JAVA=OFF -DWITH_HASKELL=OFF" + - BUILD_ARG="-DCMAKE_CXX_STANDARD=98 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF -DWITH_PYTHON=OFF -DWITH_C_GLIB=OFF -DWITH_JAVA=OFF -DWITH_HASKELL=OFF" - BUILD_ENV="-e CC=clang -e CXX=clang++" - script: build/docker/run.sh diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake index f419229..43b73e4 100644 --- a/build/cmake/DefineOptions.cmake +++ b/build/cmake/DefineOptions.cmake @@ -88,9 +88,7 @@ if(WITH_CPP) find_package(OpenSSL QUIET) CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON "OPENSSL_FOUND" OFF) - option(WITH_STDTHREADS "Build with C++ std::thread support" OFF) - CMAKE_DEPENDENT_OPTION(WITH_BOOSTTHREADS "Build with Boost threads support" OFF - "NOT WITH_STDTHREADS;Boost_FOUND" OFF) + option(WITH_STDTHREADS "Build with C++ std::thread support" ON) endif() CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON "BUILD_LIBRARIES;WITH_CPP;Boost_FOUND" OFF) @@ -107,7 +105,7 @@ CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON if(BUILD_CPP) set(boost_components) - if(WITH_BOOSTTHREADS OR BUILD_TESTING) + if(BUILD_TESTING) list(APPEND boost_components system thread) endif() if(BUILD_TESTING) @@ -206,7 +204,6 @@ message(STATUS " Library features:") message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}") message(STATUS " Build static libraries: ${WITH_STATIC_LIB}") message(STATUS " Build with Boost static link library: ${WITH_BOOST_STATIC}") -message(STATUS " Build with Boost thread support: ${WITH_BOOSTTHREADS}") message(STATUS " Build with boost/tr1/functional (forced) ${WITH_BOOST_FUNCTIONAL}") message(STATUS " Build with boost/smart_ptr (forced) ${WITH_BOOST_SMART_PTR}") message(STATUS " Build with C++ std::thread support: ${WITH_STDTHREADS}") diff --git a/build/cmake/DefinePlatformSpecifc.cmake b/build/cmake/DefinePlatformSpecifc.cmake index 626f5e5..cbd5ca8 100644 --- a/build/cmake/DefinePlatformSpecifc.cmake +++ b/build/cmake/DefinePlatformSpecifc.cmake @@ -90,9 +90,7 @@ add_definitions("-D__STDC_FORMAT_MACROS") add_definitions("-D__STDC_LIMIT_MACROS") # WITH_*THREADS selects which threading library to use -if(WITH_BOOSTTHREADS) - add_definitions("-DUSE_BOOST_THREAD=1") -elseif(WITH_STDTHREADS) +if(WITH_STDTHREADS) add_definitions("-DUSE_STD_THREAD=1") endif() diff --git a/build/cmake/README-MSYS2.md b/build/cmake/README-MSYS2.md index 02679e6..07cad92 100644 --- a/build/cmake/README-MSYS2.md +++ b/build/cmake/README-MSYS2.md @@ -43,7 +43,7 @@ Use cmake to create a MinGW makefile, out of tree (assumes you are in the top le cmake -G"MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=/mingw64/bin/mingw32-make \ -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc.exe \ -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++.exe \ - -DWITH_BOOSTTHREADS=ON -DWITH_LIBEVENT=OFF \ + -DWITH_LIBEVENT=OFF \ -DWITH_SHARED_LIB=OFF -DWITH_STATIC_LIB=ON \ -DWITH_JAVA=OFF -DWITH_PYTHON=OFF -DWITH_PERL=OFF \ ../thrift diff --git a/build/cmake/README.md b/build/cmake/README.md index ebc4f7d..e5c128b 100644 --- a/build/cmake/README.md +++ b/build/cmake/README.md @@ -30,7 +30,7 @@ or on Windows cmake -G "Visual Studio 12 2013 Win64" \ -DBOOST_ROOT=C:/3rdparty/boost_1_58_0 \ -DZLIB_ROOT=C:/3rdparty/zlib128-dll \ - -DWITH_SHARED_LIB=off -DWITH_BOOSTTHREADS=ON .. + -DWITH_SHARED_LIB=off .. and open the development environment you like with the solution or do this: diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 39d8270..5f0ae46 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -64,9 +64,6 @@ see: aclocal/ac_prog_bison.m4 */ #cmakedefine BISON_USE_PARSER_H_EXTENSION 1 -/* replaces POSIX pthread by boost::thread */ -#cmakedefine USE_BOOST_THREAD 1 - /* replaces POSIX pthread by std::thread */ #cmakedefine USE_STD_THREAD 1 diff --git a/build/wincpp/build-thrift.bat b/build/wincpp/build-thrift.bat index ba3e476..b867acf 100644 --- a/build/wincpp/build-thrift.bat +++ b/build/wincpp/build-thrift.bat @@ -134,7 +134,6 @@ IF %OPT_GENERATE% == 1 ( -DOPENSSL_USE_STATIC_LIBS=OFF ^ -DZLIB_LIBRARY=%WIN3P_ROOT%\dist\zlib-%TP_ZLIB_VERSION%\%COMPILER%\%ARCH%\lib\zlib%ZLIB_LIB_SUFFIX%.lib ^ -DZLIB_ROOT=%WIN3P_ROOT%\dist\zlib-%TP_ZLIB_VERSION%\%COMPILER%\%ARCH% ^ - -DWITH_BOOSTTHREADS=ON ^ -DWITH_SHARED_LIB=OFF ^ -DWITH_STATIC_LIB=ON || EXIT /B diff --git a/configure.ac b/configure.ac index 9885e1b..2174629 100755 --- a/configure.ac +++ b/configure.ac @@ -785,24 +785,6 @@ AC_SUBST(GCOV_CFLAGS) AC_SUBST(GCOV_CXXFLAGS) AC_SUBST(GCOV_LDFLAGS) -AC_ARG_ENABLE(boostthreads, - [ --enable-boostthreads use boost threads, instead of POSIX pthread (experimental) ], - [case "${enableval}" in - yes) ENABLE_BOOSTTHREADS=1 ;; - no) ENABLE_BOOSTTHREADS=0 ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-cov) ;; - esac], - [ENABLE_BOOSTTHREADS=2]) - - -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"]) - AC_CONFIG_HEADERS(config.h:config.hin) AC_CONFIG_HEADERS(lib/cpp/src/thrift/config.h:config.hin) AC_CONFIG_HEADERS(lib/c_glib/src/thrift/config.h:config.hin) diff --git a/contrib/transport-sample/ThriftCommon.h b/contrib/transport-sample/ThriftCommon.h index d24d1a7..e16d87d 100644 --- a/contrib/transport-sample/ThriftCommon.h +++ b/contrib/transport-sample/ThriftCommon.h @@ -16,8 +16,6 @@ // #ifdef _WIN32 //thrift is crashing when using boost threads on Mac OSX -# define USE_BOOST_THREAD 1 -# include <boost/thread.hpp> #else # include <sys/socket.h> # include <netinet/in.h> diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 1ed0bfa..9ea82c3 100755 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -103,14 +103,7 @@ if(OPENSSL_FOUND AND WITH_OPENSSL) endif() # WITH_*THREADS selects which threading library to use -if(WITH_BOOSTTHREADS) - set( thriftcpp_threads_SOURCES - src/thrift/concurrency/BoostThreadFactory.cpp - src/thrift/concurrency/BoostMonitor.cpp - src/thrift/concurrency/BoostMutex.cpp - ) - list(APPEND SYSLIBS "${Boost_LIBRARIES}") -elseif(UNIX AND NOT WITH_STDTHREADS) +if(UNIX AND NOT WITH_STDTHREADS) if(ANDROID) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") else() diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am index 83ccd9b..11d6b05 100755 --- a/lib/cpp/Makefile.am +++ b/lib/cpp/Makefile.am @@ -106,15 +106,9 @@ libthrift_la_SOURCES = src/thrift/TApplicationException.cpp \ src/thrift/server/TThreadPoolServer.cpp \ src/thrift/server/TThreadedServer.cpp -if WITH_BOOSTTHREADS -libthrift_la_SOURCES += src/thrift/concurrency/BoostThreadFactory.cpp \ - src/thrift/concurrency/BoostMonitor.cpp \ - src/thrift/concurrency/BoostMutex.cpp -else libthrift_la_SOURCES += src/thrift/concurrency/Mutex.cpp \ src/thrift/concurrency/Monitor.cpp \ src/thrift/concurrency/PosixThreadFactory.cpp -endif libthriftnb_la_SOURCES = src/thrift/server/TNonblockingServer.cpp \ src/thrift/async/TEvhttpServer.cpp \ @@ -170,7 +164,6 @@ include_thrift_HEADERS = \ include_concurrencydir = $(include_thriftdir)/concurrency include_concurrency_HEADERS = \ - src/thrift/concurrency/BoostThreadFactory.h \ src/thrift/concurrency/Exception.h \ src/thrift/concurrency/Mutex.h \ src/thrift/concurrency/Monitor.h \ diff --git a/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp b/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp deleted file mode 100644 index ebfa0b9..0000000 --- a/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <thrift/thrift-config.h> - -#include <thrift/concurrency/Monitor.h> -#include <thrift/concurrency/Exception.h> -#include <thrift/concurrency/Util.h> -#include <thrift/transport/PlatformSocket.h> -#include <thrift/stdcxx.h> - -#include <assert.h> -#include <boost/thread.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> - -namespace apache { -namespace thrift { -namespace concurrency { - -/** - * Monitor implementation using the boost thread library - * - * @version $Id:$ - */ -class Monitor::Impl : public boost::condition_variable_any { - -public: - Impl() : ownedMutex_(new Mutex()), mutex_(NULL) { init(ownedMutex_.get()); } - - Impl(Mutex* mutex) : mutex_(NULL) { init(mutex); } - - Impl(Monitor* monitor) : mutex_(NULL) { init(&(monitor->mutex())); } - - Mutex& mutex() { return *mutex_; } - void lock() { mutex().lock(); } - void unlock() { mutex().unlock(); } - - /** - * Exception-throwing version of waitForTimeRelative(), called simply - * wait(int64) for historical reasons. Timeout is in milliseconds. - * - * If the condition occurs, this function returns cleanly; on timeout or - * error an exception is thrown. - */ - void wait(int64_t timeout_ms) { - int result = waitForTimeRelative(timeout_ms); - if (result == THRIFT_ETIMEDOUT) { - throw TimedOutException(); - } else if (result != 0) { - throw TException("Monitor::wait() failed"); - } - } - - /** - * Waits until the specified timeout in milliseconds for the condition to - * occur, or waits forever if timeout_ms == 0. - * - * Returns 0 if condition occurs, THRIFT_ETIMEDOUT on timeout, or an error code. - */ - int waitForTimeRelative(int64_t timeout_ms) { - if (timeout_ms == 0LL) { - return waitForever(); - } - - assert(mutex_); - boost::timed_mutex* mutexImpl - = reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl()); - assert(mutexImpl); - - 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 - : THRIFT_ETIMEDOUT; - lock.release(); - return res; - } - - /** - * Waits until the absolute time specified using struct THRIFT_TIMESPEC. - * Returns 0 if condition occurs, THRIFT_ETIMEDOUT on timeout, or an error code. - */ - int waitForTime(const THRIFT_TIMESPEC* abstime) { - struct timeval temp; - temp.tv_sec = static_cast<long>(abstime->tv_sec); - temp.tv_usec = static_cast<long>(abstime->tv_nsec) / 1000; - return waitForTime(&temp); - } - - /** - * Waits until the absolute time specified using struct timeval. - * Returns 0 if condition occurs, THRIFT_ETIMEDOUT on timeout, or an error code. - */ - int waitForTime(const struct timeval* abstime) { - assert(mutex_); - boost::timed_mutex* mutexImpl = static_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl()); - assert(mutexImpl); - - struct timeval currenttime; - Util::toTimeval(currenttime, Util::currentTime()); - - long tv_sec = static_cast<long>(abstime->tv_sec - currenttime.tv_sec); - long tv_usec = static_cast<long>(abstime->tv_usec - currenttime.tv_usec); - if (tv_sec < 0) - tv_sec = 0; - if (tv_usec < 0) - tv_usec = 0; - - 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_usec)) - ? 0 - : THRIFT_ETIMEDOUT; - lock.release(); - return res; - } - - /** - * Waits forever until the condition occurs. - * Returns 0 if condition occurs, or an error code otherwise. - */ - int waitForever() { - assert(mutex_); - boost::timed_mutex* mutexImpl - = reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl()); - assert(mutexImpl); - - boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock); - ((boost::condition_variable_any*)this)->wait(lock); - lock.release(); - return 0; - } - - void notify() { notify_one(); } - - void notifyAll() { notify_all(); } - -private: - void init(Mutex* mutex) { mutex_ = mutex; } - - stdcxx::scoped_ptr<Mutex> ownedMutex_; - Mutex* mutex_; -}; - -Monitor::Monitor() : impl_(new Monitor::Impl()) { -} -Monitor::Monitor(Mutex* mutex) : impl_(new Monitor::Impl(mutex)) { -} -Monitor::Monitor(Monitor* monitor) : impl_(new Monitor::Impl(monitor)) { -} - -Monitor::~Monitor() { - delete impl_; -} - -Mutex& Monitor::mutex() const { - return const_cast<Monitor::Impl*>(impl_)->mutex(); -} - -void Monitor::lock() const { - const_cast<Monitor::Impl*>(impl_)->lock(); -} - -void Monitor::unlock() const { - const_cast<Monitor::Impl*>(impl_)->unlock(); -} - -void Monitor::wait(int64_t timeout) const { - const_cast<Monitor::Impl*>(impl_)->wait(timeout); -} - -int Monitor::waitForTime(const THRIFT_TIMESPEC* abstime) const { - return const_cast<Monitor::Impl*>(impl_)->waitForTime(abstime); -} - -int Monitor::waitForTime(const timeval* abstime) const { - return const_cast<Monitor::Impl*>(impl_)->waitForTime(abstime); -} - -int Monitor::waitForTimeRelative(int64_t timeout_ms) const { - return const_cast<Monitor::Impl*>(impl_)->waitForTimeRelative(timeout_ms); -} - -int Monitor::waitForever() const { - return const_cast<Monitor::Impl*>(impl_)->waitForever(); -} - -void Monitor::notify() const { - const_cast<Monitor::Impl*>(impl_)->notify(); -} - -void Monitor::notifyAll() const { - const_cast<Monitor::Impl*>(impl_)->notifyAll(); -} -} -} -} // apache::thrift::concurrency diff --git a/lib/cpp/src/thrift/concurrency/BoostMutex.cpp b/lib/cpp/src/thrift/concurrency/BoostMutex.cpp deleted file mode 100644 index 4e556df..0000000 --- a/lib/cpp/src/thrift/concurrency/BoostMutex.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <thrift/thrift-config.h> - -#include <thrift/concurrency/Mutex.h> -#include <thrift/concurrency/Util.h> -#include <thrift/Thrift.h> - -#include <cassert> -#include <boost/thread.hpp> -#include <boost/thread/mutex.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> - -namespace apache { -namespace thrift { -namespace concurrency { - -/** - * Implementation of Mutex class using boost::timed_mutex - * - * Methods throw boost::lock_error on error. - * - * @version $Id:$ - */ -class Mutex::impl : public boost::timed_mutex {}; - -Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) { - THRIFT_UNUSED_VARIABLE(init); -} - -void* Mutex::getUnderlyingImpl() const { - return impl_.get(); -} - -void Mutex::lock() const { - impl_->lock(); -} - -bool Mutex::trylock() const { - return impl_->try_lock(); -} - -bool Mutex::timedlock(int64_t ms) const { - return impl_->timed_lock(boost::get_system_time() + boost::posix_time::milliseconds(ms)); -} - -void Mutex::unlock() const { - impl_->unlock(); -} - -void Mutex::DEFAULT_INITIALIZER(void* arg) { - THRIFT_UNUSED_VARIABLE(arg); -} -} -} -} // apache::thrift::concurrency diff --git a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp deleted file mode 100644 index d7d8d54..0000000 --- a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <thrift/thrift-config.h> - -#if USE_BOOST_THREAD - -#include <thrift/concurrency/BoostThreadFactory.h> -#include <thrift/concurrency/Exception.h> -#include <thrift/stdcxx.h> -#include <cassert> - -#include <boost/thread.hpp> - -namespace apache { -namespace thrift { - -using stdcxx::bind; -using stdcxx::scoped_ptr; -using stdcxx::shared_ptr; -using stdcxx::weak_ptr; - -namespace concurrency { - -/** - * The boost thread class. - * - * @version $Id:$ - */ -class BoostThread : public Thread { -public: - enum STATE { uninitialized, starting, started, stopping, stopped }; - - static void* threadMain(void* arg); - -private: - scoped_ptr<boost::thread> thread_; - Monitor monitor_; - STATE state_; - weak_ptr<BoostThread> self_; - bool detached_; - -public: - BoostThread(bool detached, shared_ptr<Runnable> runnable) - : state_(uninitialized), detached_(detached) { - this->Thread::runnable(runnable); - } - - ~BoostThread() { - if (!detached_ && thread_->joinable()) { - try { - join(); - } catch (...) { - // We're really hosed. - } - } - } - - STATE getState() const - { - Synchronized sync(monitor_); - return state_; - } - - void setState(STATE newState) - { - Synchronized sync(monitor_); - state_ = newState; - - // unblock start() with the knowledge that the thread has actually - // started running, which avoids a race in detached threads. - if (newState == started) { - monitor_.notify(); - } - } - - void start() { - // Create reference - shared_ptr<BoostThread>* selfRef = new shared_ptr<BoostThread>(); - *selfRef = self_.lock(); - - setState(starting); - - Synchronized sync(monitor_); - - thread_.reset(new boost::thread(bind(threadMain, (void*)selfRef))); - - if (detached_) - thread_->detach(); - - // Wait for the thread to start and get far enough to grab everything - // that it needs from the calling context, thus absolving the caller - // from being required to hold on to runnable indefinitely. - monitor_.wait(); - } - - void join() { - if (!detached_ && getState() != uninitialized) { - thread_->join(); - } - } - - Thread::id_t getId() { return thread_.get() ? thread_->get_id() : boost::thread::id(); } - - shared_ptr<Runnable> runnable() const { return Thread::runnable(); } - - void runnable(shared_ptr<Runnable> value) { Thread::runnable(value); } - - void weakRef(shared_ptr<BoostThread> self) { - assert(self.get() == this); - self_ = weak_ptr<BoostThread>(self); - } -}; - -void* BoostThread::threadMain(void* arg) { - shared_ptr<BoostThread> thread = *(shared_ptr<BoostThread>*)arg; - delete reinterpret_cast<shared_ptr<BoostThread>*>(arg); - - thread->setState(started); - thread->runnable()->run(); - - if (thread->getState() != stopping && thread->getState() != stopped) { - thread->setState(stopping); - } - return (void*)0; -} - -BoostThreadFactory::BoostThreadFactory(bool detached) - : ThreadFactory(detached) { -} - -shared_ptr<Thread> BoostThreadFactory::newThread(shared_ptr<Runnable> runnable) const { - shared_ptr<BoostThread> result = shared_ptr<BoostThread>(new BoostThread(isDetached(), runnable)); - result->weakRef(result); - runnable->thread(result); - return result; -} - -Thread::id_t BoostThreadFactory::getCurrentThreadId() const { - return boost::this_thread::get_id(); -} -} -} -} // apache::thrift::concurrency - -#endif // USE_BOOST_THREAD diff --git a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.h b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.h deleted file mode 100644 index bf11a70..0000000 --- a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef _THRIFT_CONCURRENCY_BOOSTTHREADFACTORY_H_ -#define _THRIFT_CONCURRENCY_BOOSTTHREADFACTORY_H_ 1 - -#include <thrift/concurrency/Monitor.h> -#include <thrift/concurrency/Thread.h> -#include <thrift/stdcxx.h> - -namespace apache { -namespace thrift { -namespace concurrency { - -/** - * A thread factory to create posix threads - * - * @version $Id:$ - */ -class BoostThreadFactory : public ThreadFactory { - -public: - /** - * Boost thread factory. All threads created by a factory are reference-counted - * via stdcxx::shared_ptr. The factory guarantees that threads and the Runnable tasks they - * host will be properly cleaned up once the last strong reference to both is given up. - * - * Threads are created with the specified boost policy, priority, stack-size. A detachable thread - * is not joinable. - * - * By default threads are not joinable. - */ - - BoostThreadFactory(bool detached = true); - - // From ThreadFactory; - stdcxx::shared_ptr<Thread> newThread(stdcxx::shared_ptr<Runnable> runnable) const; - - // From ThreadFactory; - Thread::id_t getCurrentThreadId() const; -}; - -} -} -} // apache::thrift::concurrency - -#endif // #ifndef _THRIFT_CONCURRENCY_BOOSTTHREADFACTORY_H_ diff --git a/lib/cpp/src/thrift/concurrency/PlatformThreadFactory.h b/lib/cpp/src/thrift/concurrency/PlatformThreadFactory.h index 545b572..99b4403 100644 --- a/lib/cpp/src/thrift/concurrency/PlatformThreadFactory.h +++ b/lib/cpp/src/thrift/concurrency/PlatformThreadFactory.h @@ -22,9 +22,7 @@ // clang-format off #include <thrift/thrift-config.h> -#if USE_BOOST_THREAD -# include <thrift/concurrency/BoostThreadFactory.h> -#elif USE_STD_THREAD +#if USE_STD_THREAD # include <thrift/concurrency/StdThreadFactory.h> #else # include <thrift/concurrency/PosixThreadFactory.h> @@ -36,9 +34,7 @@ namespace thrift { namespace concurrency { // clang-format off -#if USE_BOOST_THREAD - typedef BoostThreadFactory PlatformThreadFactory; -#elif USE_STD_THREAD +#if USE_STD_THREAD typedef StdThreadFactory PlatformThreadFactory; #else typedef PosixThreadFactory PlatformThreadFactory; diff --git a/lib/cpp/src/thrift/concurrency/Thread.h b/lib/cpp/src/thrift/concurrency/Thread.h index 788623b..7e2d251 100644 --- a/lib/cpp/src/thrift/concurrency/Thread.h +++ b/lib/cpp/src/thrift/concurrency/Thread.h @@ -25,9 +25,7 @@ #include <thrift/thrift-config.h> -#if USE_BOOST_THREAD -#include <boost/thread.hpp> -#elif USE_STD_THREAD +#if USE_STD_THREAD #include <thread> #else #ifdef HAVE_PTHREAD_H @@ -80,12 +78,7 @@ private: class Thread { public: -#if USE_BOOST_THREAD - typedef boost::thread::id id_t; - - static inline bool is_current(id_t t) { return t == boost::this_thread::get_id(); } - static inline id_t get_current() { return boost::this_thread::get_id(); } -#elif USE_STD_THREAD +#if USE_STD_THREAD typedef std::thread::id id_t; static inline bool is_current(id_t t) { return t == std::this_thread::get_id(); } diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp index 194d59f..1031ec0 100644 --- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp +++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp @@ -1119,7 +1119,7 @@ void TNonblockingServer::registerEvents(event_base* user_event_base) { // Launch all the secondary IO threads in separate threads if (ioThreads_.size() > 1) { ioThreadFactory_.reset(new PlatformThreadFactory( -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD PlatformThreadFactory::OTHER, // scheduler PlatformThreadFactory::NORMAL, // priority 1, // stack size (MB) diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp index 2e0ccf5..d2683b0 100644 --- a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp +++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp @@ -28,13 +28,7 @@ namespace thrift { namespace transport { TWinsockSingleton::instance_ptr TWinsockSingleton::instance_ptr_(NULL); -#if USE_BOOST_THREAD -boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT; -#elif USE_STD_THREAD std::once_flag TWinsockSingleton::flags_; -#else -#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD -#endif //------------------------------------------------------------------------------ TWinsockSingleton::TWinsockSingleton(void) { @@ -55,11 +49,7 @@ TWinsockSingleton::~TWinsockSingleton(void) { //------------------------------------------------------------------------------ void TWinsockSingleton::create(void) { -#if USE_BOOST_THREAD - boost::call_once(init, flags_); -#elif USE_STD_THREAD std::call_once(flags_, init); -#endif } //------------------------------------------------------------------------------ diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.h b/lib/cpp/src/thrift/windows/TWinsockSingleton.h index 0eab6d4..50458a9 100644 --- a/lib/cpp/src/thrift/windows/TWinsockSingleton.h +++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.h @@ -33,13 +33,7 @@ // boost #include <boost/noncopyable.hpp> -#if USE_BOOST_THREAD -#include <boost/thread/once.hpp> -#elif USE_STD_THREAD #include <mutex> -#else -#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD -#endif #include <thrift/stdcxx.h> @@ -70,13 +64,7 @@ private: private: static instance_ptr instance_ptr_; -#if USE_BOOST_THREAD - static boost::once_flag flags_; -#elif USE_STD_THREAD static std::once_flag flags_; -#else -#error Need a non-Boost non-C++11 way to track single initialization here. -#endif }; } } diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h index bc4aa42..a5f4457 100644 --- a/lib/cpp/src/thrift/windows/config.h +++ b/lib/cpp/src/thrift/windows/config.h @@ -31,9 +31,6 @@ // use std::thread in MSVC11 (2012) or newer and in MinGW #if (_MSC_VER >= 1700) || defined(__MINGW32__) #define USE_STD_THREAD 1 -#else -// otherwise use boost threads -#define USE_BOOST_THREAD 1 #endif // Something that defines PRId64 is required to build diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt index 261382f..82d47a6 100644 --- a/lib/cpp/test/CMakeLists.txt +++ b/lib/cpp/test/CMakeLists.txt @@ -82,7 +82,7 @@ set(UnitTest_SOURCES TServerTransportTest.cpp ) -if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS AND NOT MSVC AND NOT MINGW) +if(NOT WITH_STDTHREADS AND NOT MSVC AND NOT MINGW) list(APPEND UnitTest_SOURCES concurrency/MutexTest.cpp) list(APPEND UnitTest_SOURCES concurrency/RWMutexStarveTest.cpp) endif() diff --git a/lib/cpp/test/Makefile.am b/lib/cpp/test/Makefile.am index 4b9f77d..d645a65 100755 --- a/lib/cpp/test/Makefile.am +++ b/lib/cpp/test/Makefile.am @@ -135,11 +135,9 @@ UnitTests_SOURCES = \ TServerTransportTest.cpp \ TTransportCheckThrow.h -if !WITH_BOOSTTHREADS UnitTests_SOURCES += \ concurrency/MutexTest.cpp \ concurrency/RWMutexStarveTest.cpp -endif UnitTests_LDADD = \ libtestgencpp.la \ diff --git a/lib/cpp/test/TNonblockingSSLServerTest.cpp b/lib/cpp/test/TNonblockingSSLServerTest.cpp index 3e9700f..2efb140 100644 --- a/lib/cpp/test/TNonblockingSSLServerTest.cpp +++ b/lib/cpp/test/TNonblockingSSLServerTest.cpp @@ -221,7 +221,7 @@ protected: apache::thrift::stdcxx::scoped_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory( new apache::thrift::concurrency::PlatformThreadFactory( -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD concurrency::PlatformThreadFactory::OTHER, concurrency::PlatformThreadFactory::NORMAL, 1, #endif diff --git a/lib/cpp/test/TNonblockingServerTest.cpp b/lib/cpp/test/TNonblockingServerTest.cpp index 63d8a04..5e10907 100644 --- a/lib/cpp/test/TNonblockingServerTest.cpp +++ b/lib/cpp/test/TNonblockingServerTest.cpp @@ -148,7 +148,7 @@ protected: shared_ptr<ThreadFactory> threadFactory( new PlatformThreadFactory( -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD PlatformThreadFactory::OTHER, PlatformThreadFactory::NORMAL, 1, #endif diff --git a/lib/cpp/test/concurrency/ThreadManagerTests.h b/lib/cpp/test/concurrency/ThreadManagerTests.h index 9ecd6ba..15a43ff 100644 --- a/lib/cpp/test/concurrency/ThreadManagerTests.h +++ b/lib/cpp/test/concurrency/ThreadManagerTests.h @@ -111,7 +111,7 @@ public: shared_ptr<PlatformThreadFactory> threadFactory = shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory(false)); -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD threadFactory->setPriority(PosixThreadFactory::HIGHEST); #endif threadManager->threadFactory(threadFactory); @@ -260,7 +260,7 @@ public: shared_ptr<PlatformThreadFactory> threadFactory = shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()); -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD threadFactory->setPriority(PosixThreadFactory::HIGHEST); #endif threadManager->threadFactory(threadFactory); @@ -401,7 +401,7 @@ public: return false; } -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD // test once with a detached thread factory and once with a joinable thread factory shared_ptr<PosixThreadFactory> threadFactory @@ -426,7 +426,7 @@ public: shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(1); threadManager->threadFactory(threadFactory); -#if !USE_BOOST_THREAD && !USE_STD_THREAD +#if !USE_STD_THREAD threadFactory->setPriority(PosixThreadFactory::HIGHEST); // verify we cannot change the thread factory to one with the opposite detached setting