diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:11:01 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2019-12-05 15:11:01 +0900 |
commit | 3fdc3e5ee96dca5b11d1694975a65200787eab86 (patch) | |
tree | 5c1733853892b8397d67706fa453a9bd978d2102 /boost/thread/pthread | |
parent | 88e602c57797660ebe0f9e15dbd64c1ff16dead3 (diff) | |
download | boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.gz boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.tar.bz2 boost-3fdc3e5ee96dca5b11d1694975a65200787eab86.zip |
Imported Upstream version 1.66.0upstream/1.66.0
Diffstat (limited to 'boost/thread/pthread')
-rw-r--r-- | boost/thread/pthread/condition_variable.hpp | 8 | ||||
-rw-r--r-- | boost/thread/pthread/condition_variable_fwd.hpp | 34 | ||||
-rw-r--r-- | boost/thread/pthread/pthread_mutex_scoped_lock.hpp | 2 | ||||
-rw-r--r-- | boost/thread/pthread/shared_mutex.hpp | 1 | ||||
-rw-r--r-- | boost/thread/pthread/thread_data.hpp | 18 | ||||
-rw-r--r-- | boost/thread/pthread/thread_heap_alloc.hpp | 34 | ||||
-rw-r--r-- | boost/thread/pthread/timespec.hpp | 19 |
7 files changed, 70 insertions, 46 deletions
diff --git a/boost/thread/pthread/condition_variable.hpp b/boost/thread/pthread/condition_variable.hpp index 5dcb3a0e38..b66b710a24 100644 --- a/boost/thread/pthread/condition_variable.hpp +++ b/boost/thread/pthread/condition_variable.hpp @@ -79,7 +79,7 @@ namespace boost pthread_mutex_t* the_mutex = &internal_mutex; guard.activate(m); res = pthread_cond_wait(&cond,the_mutex); - check_for_interruption.check(); + check_for_interruption.unlock_if_locked(); guard.deactivate(); #else pthread_mutex_t* the_mutex = m.mutex()->native_handle(); @@ -113,7 +113,7 @@ namespace boost pthread_mutex_t* the_mutex = &internal_mutex; guard.activate(m); cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout); - check_for_interruption.check(); + check_for_interruption.unlock_if_locked(); guard.deactivate(); #else pthread_mutex_t* the_mutex = m.mutex()->native_handle(); @@ -190,7 +190,7 @@ namespace boost #endif guard.activate(m); res=pthread_cond_wait(&cond,&internal_mutex); - check_for_interruption.check(); + check_for_interruption.unlock_if_locked(); guard.deactivate(); } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS @@ -420,7 +420,7 @@ namespace boost #endif guard.activate(m); res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout); - check_for_interruption.check(); + check_for_interruption.unlock_if_locked(); guard.deactivate(); } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS diff --git a/boost/thread/pthread/condition_variable_fwd.hpp b/boost/thread/pthread/condition_variable_fwd.hpp index 802a5cc674..0ea34e238d 100644 --- a/boost/thread/pthread/condition_variable_fwd.hpp +++ b/boost/thread/pthread/condition_variable_fwd.hpp @@ -53,9 +53,9 @@ namespace boost class condition_variable { private: -#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS +//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS pthread_mutex_t internal_mutex; -#endif +//#endif pthread_cond_t cond; public: @@ -69,16 +69,8 @@ namespace boost unique_lock<mutex>& lock, struct timespec const &timeout) { -#if ! defined BOOST_THREAD_USEFIXES_TIMESPEC - return do_wait_until(lock, boost::detail::timespec_plus(timeout, boost::detail::timespec_now())); -#elif ! defined BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC - //using namespace chrono; - //nanoseconds ns = chrono::system_clock::now().time_since_epoch(); - - struct timespec ts = boost::detail::timespec_now_realtime(); - //ts.tv_sec = static_cast<long>(chrono::duration_cast<chrono::seconds>(ns).count()); - //ts.tv_nsec = static_cast<long>((ns - chrono::duration_cast<chrono::seconds>(ns)).count()); - return do_wait_until(lock, boost::detail::timespec_plus(timeout, ts)); +#if defined BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC + return do_wait_until(lock, boost::detail::timespec_plus(timeout, boost::detail::timespec_now_monotonic())); #else // old behavior was fine for monotonic return do_wait_until(lock, boost::detail::timespec_plus(timeout, boost::detail::timespec_now_realtime())); @@ -90,31 +82,37 @@ namespace boost condition_variable() { int res; -#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS +//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS + // Even if it is not used, the internal_mutex exists (see + // above) and must be initialized (etc) in case some + // compilation units provide interruptions and others + // don't. res=pthread_mutex_init(&internal_mutex,NULL); if(res) { boost::throw_exception(thread_resource_error(res, "boost::condition_variable::condition_variable() constructor failed in pthread_mutex_init")); } -#endif +//#endif res = detail::monotonic_pthread_cond_init(cond); if (res) { -#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS +//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS + // ditto BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex)); -#endif +//#endif boost::throw_exception(thread_resource_error(res, "boost::condition_variable::condition_variable() constructor failed in detail::monotonic_pthread_cond_init")); } } ~condition_variable() { int ret; -#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS +//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS + // ditto do { ret = pthread_mutex_destroy(&internal_mutex); } while (ret == EINTR); BOOST_ASSERT(!ret); -#endif +//#endif do { ret = pthread_cond_destroy(&cond); } while (ret == EINTR); diff --git a/boost/thread/pthread/pthread_mutex_scoped_lock.hpp b/boost/thread/pthread/pthread_mutex_scoped_lock.hpp index e3b9990311..9b327a6c6d 100644 --- a/boost/thread/pthread/pthread_mutex_scoped_lock.hpp +++ b/boost/thread/pthread/pthread_mutex_scoped_lock.hpp @@ -30,7 +30,7 @@ namespace boost BOOST_VERIFY(!pthread_mutex_unlock(m)); locked=false; } - void check() BOOST_NOEXCEPT + void unlock_if_locked() BOOST_NOEXCEPT { if(locked) { diff --git a/boost/thread/pthread/shared_mutex.hpp b/boost/thread/pthread/shared_mutex.hpp index b427b0f16a..e4ec24fe3f 100644 --- a/boost/thread/pthread/shared_mutex.hpp +++ b/boost/thread/pthread/shared_mutex.hpp @@ -20,7 +20,6 @@ #include <boost/chrono/ceil.hpp> #endif #include <boost/thread/detail/delete.hpp> -#include <boost/assert.hpp> #include <boost/config/abi_prefix.hpp> diff --git a/boost/thread/pthread/thread_data.hpp b/boost/thread/pthread/thread_data.hpp index 836e6927c8..f6575f1c22 100644 --- a/boost/thread/pthread/thread_data.hpp +++ b/boost/thread/pthread/thread_data.hpp @@ -50,7 +50,11 @@ namespace boost // stack void set_stack_size(std::size_t size) BOOST_NOEXCEPT { if (size==0) return; +#ifdef BOOST_THREAD_USES_GETPAGESIZE std::size_t page_size = getpagesize(); +#else + std::size_t page_size = ::sysconf( _SC_PAGESIZE); +#endif #ifdef PTHREAD_STACK_MIN if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN; #endif @@ -209,7 +213,7 @@ namespace boost BOOST_VERIFY(!pthread_mutex_lock(m)); } } - void check() + void unlock_if_locked() { if ( ! done) { if (set) @@ -229,7 +233,7 @@ namespace boost ~interruption_checker() BOOST_NOEXCEPT_IF(false) { - check(); + unlock_if_locked(); } }; #endif @@ -240,10 +244,12 @@ namespace boost namespace hidden { void BOOST_THREAD_DECL sleep_for(const timespec& ts); - void BOOST_THREAD_DECL sleep_until(const timespec& ts); + void BOOST_THREAD_DECL sleep_until_realtime(const timespec& ts); } #ifdef BOOST_THREAD_USES_CHRONO + template <class Rep, class Period> + void sleep_for(const chrono::duration<Rep, Period>& d); #ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY inline @@ -259,10 +265,12 @@ namespace boost namespace hidden { void BOOST_THREAD_DECL sleep_for(const timespec& ts); - void BOOST_THREAD_DECL sleep_until(const timespec& ts); + void BOOST_THREAD_DECL sleep_until_realtime(const timespec& ts); } #ifdef BOOST_THREAD_USES_CHRONO + template <class Rep, class Period> + void sleep_for(const chrono::duration<Rep, Period>& d); #ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY inline @@ -284,7 +292,7 @@ namespace boost #endif inline void sleep(system_time const& abs_time) { - return boost::this_thread::hidden::sleep_until(boost::detail::to_timespec(abs_time)); + return boost::this_thread::hidden::sleep_until_realtime(boost::detail::to_timespec(abs_time)); } template<typename TimeDuration> diff --git a/boost/thread/pthread/thread_heap_alloc.hpp b/boost/thread/pthread/thread_heap_alloc.hpp index 7828318f05..dec7b661d7 100644 --- a/boost/thread/pthread/thread_heap_alloc.hpp +++ b/boost/thread/pthread/thread_heap_alloc.hpp @@ -16,8 +16,13 @@ namespace boost { return new T(); } - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) && ! defined (BOOST_NO_CXX11_RVALUE_REFERENCES) + template<typename T,typename... Args> + inline T* heap_new(Args&&... args) + { + return new T(static_cast<Args&&>(args)...); + } +#elif ! defined BOOST_NO_CXX11_RVALUE_REFERENCES template<typename T,typename A1> inline T* heap_new(A1&& a1) { @@ -61,6 +66,31 @@ namespace boost { return new T(a1,a2,a3,a4); } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5) + { + return new T(a1,a2,a3,a4,a5); + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6) + { + return new T(a1,a2,a3,a4,a5,a6); + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7) + { + return new T(a1,a2,a3,a4,a5,a6,a7); + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8) + { + return new T(a1,a2,a3,a4,a5,a6,a7,a8); + } + template<typename T,typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8,typename A9> + inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8,A9 a9) + { + return new T(a1,a2,a3,a4,a5,a6,a7,a8,a9); + } template<typename T,typename A1> inline T* heap_new(A1 const& a1) diff --git a/boost/thread/pthread/timespec.hpp b/boost/thread/pthread/timespec.hpp index 74583ed0eb..1fb8de94c8 100644 --- a/boost/thread/pthread/timespec.hpp +++ b/boost/thread/pthread/timespec.hpp @@ -71,32 +71,21 @@ namespace boost { return (ts.tv_sec >= 0) || (ts.tv_nsec >= 0); } - inline timespec timespec_now() +#if defined BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC + + inline timespec timespec_now_monotonic() { timespec ts; -#if defined CLOCK_MONOTONIC && defined BOOST_THREAD_USEFIXES_TIMESPEC if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) ) { ts.tv_sec = 0; ts.tv_nsec = 0; BOOST_ASSERT(0 && "Boost::Thread - Internal Error"); } -#elif defined(BOOST_THREAD_TIMESPEC_MAC_API) - timeval tv; - ::gettimeofday(&tv, 0); - ts.tv_sec = tv.tv_sec; - ts.tv_nsec = tv.tv_usec * 1000; -#else - if ( ::clock_gettime( CLOCK_REALTIME, &ts ) ) - { - ts.tv_sec = 0; - ts.tv_nsec = 0; - BOOST_ASSERT(0 && "Boost::Thread - Internal Error"); - } -#endif return ts; } +#endif inline timespec timespec_now_realtime() { |