From 8b610e7c0a64cbfbfb859d7fe43e8600f61de5d7 Mon Sep 17 00:00:00 2001 From: Vizor Date: Thu, 8 Mar 2018 15:53:53 +0100 Subject: [PATCH 1/2] United handling of wait_for_single_object United handling of wait_for_single_object (WaitForSingleObject). --- .../sync/windows/winapi_wrapper_common.hpp | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp b/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp index 428a26e..2f1efa0 100644 --- a/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp +++ b/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp @@ -33,55 +33,38 @@ namespace ipcdetail { inline void winapi_wrapper_wait_for_single_object(void *handle) { - unsigned long ret = winapi::wait_for_single_object(handle, winapi::infinite_time); - if(ret != winapi::wait_object_0){ - if(ret != winapi::wait_abandoned){ - error_info err = system_error_code(); - throw interprocess_exception(err); - } - else{ //Special case for orphaned mutexes - winapi::release_mutex(handle); - throw interprocess_exception(owner_dead_error); - } - } + winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::pos_infin); } inline bool winapi_wrapper_try_wait_for_single_object(void *handle) { - unsigned long ret = winapi::wait_for_single_object(handle, 0); - if(ret == winapi::wait_object_0){ - return true; - } - else if(ret == winapi::wait_timeout){ - return false; - } - else{ - error_info err = system_error_code(); - throw interprocess_exception(err); - } + return winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::min_date_time); } inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time) { - //Windows does not support infinity abs_time so check it - if(abs_time == boost::posix_time::pos_infin){ - winapi_wrapper_wait_for_single_object(handle); - return true; - } const boost::posix_time::ptime cur_time = microsec_clock::universal_time(); //Windows uses relative wait times so check for negative waits //and implement as 0 wait to allow try-semantics as POSIX mandates. - unsigned long ret = winapi::wait_for_single_object - ( handle - , (abs_time <= cur_time) ? 0u - : (abs_time - cur_time).total_milliseconds() - ); + unsigned long time = 0u; + if (abs_time == boost::posix_time::pos_infin){ + time = winapi::infinite_time; + } + else if(abs_time > cur_time){ + time = (abs_time - cur_time).total_milliseconds(); + } + + unsigned long ret = winapi::wait_for_single_object(handle, time); if(ret == winapi::wait_object_0){ return true; } else if(ret == winapi::wait_timeout){ return false; } + else if(ret == winapi::wait_abandoned){ //Special case for orphaned mutexes + winapi::release_mutex(handle); + throw interprocess_exception(owner_dead_error); + } else{ error_info err = system_error_code(); throw interprocess_exception(err); @@ -94,4 +77,4 @@ inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boos #include -#endif //BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP +#endif //BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP From 6483b1ced5d1ad496d8a03491fcc216ba7a9ff2c Mon Sep 17 00:00:00 2001 From: Vizor Date: Tue, 22 Jan 2019 15:16:09 +0100 Subject: [PATCH 2/2] Fixed undeclared winapi_wrapper_timed_wait_for_single_object() Declaration of winapi_wrapper_timed_wait_for_single_object() placed above usage of this function. --- .../boost/interprocess/sync/windows/winapi_wrapper_common.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp b/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp index 2f1efa0..0bc6a2d 100644 --- a/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp +++ b/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp @@ -31,6 +31,8 @@ namespace boost { namespace interprocess { namespace ipcdetail { +inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time); + inline void winapi_wrapper_wait_for_single_object(void *handle) { winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::pos_infin);