From dcafe1e17d873859298926669234b00b9781004b Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sat, 29 Apr 2017 16:15:57 +0200 Subject: [PATCH] Add noexcept(false) in destructor that could throw in C++11. --- .../thread/pthread/condition_variable.hpp | 26 ++++++++++++++++--- include/boost/thread/pthread/thread_data.hpp | 15 ++++++++--- .../boost/thread/win32/condition_variable.hpp | 22 ++++++++++++---- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/include/boost/thread/pthread/condition_variable.hpp b/include/boost/thread/pthread/condition_variable.hpp index 46f49ce8..184ca900 100644 --- a/include/boost/thread/pthread/condition_variable.hpp +++ b/include/boost/thread/pthread/condition_variable.hpp @@ -45,9 +45,17 @@ namespace boost m_.unlock(); m=&m_; } - ~lock_on_exit() + void deactivate() { - if(m) + if (m) + { + m->lock(); + } + m = 0; + } + ~lock_on_exit() BOOST_NOEXCEPT_IF(false) + { + if (m) { m->lock(); } @@ -70,10 +78,13 @@ namespace boost detail::interruption_checker check_for_interruption(&internal_mutex,&cond); pthread_mutex_t* the_mutex = &internal_mutex; guard.activate(m); + res = pthread_cond_wait(&cond,the_mutex); + //check_for_interruption.check(); + //guard.deactivate(); #else pthread_mutex_t* the_mutex = m.mutex()->native_handle(); -#endif res = pthread_cond_wait(&cond,the_mutex); +#endif } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS this_thread::interruption_point(); @@ -101,10 +112,13 @@ namespace boost detail::interruption_checker check_for_interruption(&internal_mutex,&cond); pthread_mutex_t* the_mutex = &internal_mutex; guard.activate(m); + cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout); + //check_for_interruption.check(); + //guard.deactivate(); #else pthread_mutex_t* the_mutex = m.mutex()->native_handle(); -#endif cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout); +#endif } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS this_thread::interruption_point(); @@ -176,6 +190,8 @@ namespace boost #endif guard.activate(m); res=pthread_cond_wait(&cond,&internal_mutex); + //check_for_interruption.check(); + //guard.deactivate(); } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS this_thread::interruption_point(); @@ -404,6 +420,8 @@ namespace boost #endif guard.activate(m); res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout); + //check_for_interruption.check(); + //guard.deactivate(); } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS this_thread::interruption_point(); diff --git a/include/boost/thread/pthread/thread_data.hpp b/include/boost/thread/pthread/thread_data.hpp index 458bcd54..836e6927 100644 --- a/include/boost/thread/pthread/thread_data.hpp +++ b/include/boost/thread/pthread/thread_data.hpp @@ -177,6 +177,7 @@ namespace boost thread_data_base* const thread_info; pthread_mutex_t* m; bool set; + bool done; void check_for_interruption() { @@ -193,7 +194,7 @@ namespace boost public: explicit interruption_checker(pthread_mutex_t* cond_mutex,pthread_cond_t* cond): thread_info(detail::get_current_thread_data()),m(cond_mutex), - set(thread_info && thread_info->interrupt_enabled) + set(thread_info && thread_info->interrupt_enabled), done(false) { if(set) { @@ -208,9 +209,10 @@ namespace boost BOOST_VERIFY(!pthread_mutex_lock(m)); } } - ~interruption_checker() + void check() { - if(set) + if ( ! done) { + if (set) { BOOST_VERIFY(!pthread_mutex_unlock(m)); lock_guard guard(thread_info->data_mutex); @@ -221,6 +223,13 @@ namespace boost { BOOST_VERIFY(!pthread_mutex_unlock(m)); } + done = true; + } + } + + ~interruption_checker() BOOST_NOEXCEPT_IF(false) + { + check(); } }; #endif diff --git a/include/boost/thread/win32/condition_variable.hpp b/include/boost/thread/win32/condition_variable.hpp index 23e9e444..37cec62e 100644 --- a/include/boost/thread/win32/condition_variable.hpp +++ b/include/boost/thread/win32/condition_variable.hpp @@ -153,9 +153,14 @@ namespace boost lock.unlock(); unlocked=true; } - ~relocker() + void lock() { - if(unlocked) + lock.lock(); + unlocked=false; + } + ~relocker() BOOST_NOEXCEPT_IF(false) + { + if (unlocked) { lock.lock(); } @@ -215,11 +220,12 @@ namespace boost template bool do_wait(lock_type& lock,timeout abs_time) { - relocker locker(lock); + //relocker locker(lock); + try { entry_manager entry(get_wait_entry(), internal_mutex); - locker.unlock(); + lock.unlock(); bool woken=false; while(!woken) @@ -231,7 +237,13 @@ namespace boost woken=entry->woken(); } - return woken; + lock.lock(); + } + catch (E& ex ) + { + throw; + } + return woken; } template