1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
12 #define BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
24 #include <boost/interprocess/detail/win32_api.hpp>
25 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
26 #include <boost/interprocess/errors.hpp>
27 #include <boost/interprocess/exceptions.hpp>
31 namespace interprocess {
34 inline void winapi_wrapper_wait_for_single_object(void *handle)
36 unsigned long ret = winapi::wait_for_single_object(handle, winapi::infinite_time);
37 if(ret != winapi::wait_object_0){
38 if(ret != winapi::wait_abandoned){
39 error_info err = system_error_code();
40 throw interprocess_exception(err);
42 else{ //Special case for orphaned mutexes
43 winapi::release_mutex(handle);
44 throw interprocess_exception(owner_dead_error);
49 inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
51 unsigned long ret = winapi::wait_for_single_object(handle, 0);
52 if(ret == winapi::wait_object_0){
55 else if(ret == winapi::wait_timeout){
59 error_info err = system_error_code();
60 throw interprocess_exception(err);
64 inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time)
66 //Windows does not support infinity abs_time so check it
67 if(abs_time == boost::posix_time::pos_infin){
68 winapi_wrapper_wait_for_single_object(handle);
71 const boost::posix_time::ptime cur_time = microsec_clock::universal_time();
72 //Windows uses relative wait times so check for negative waits
73 //and implement as 0 wait to allow try-semantics as POSIX mandates.
74 unsigned long ret = winapi::wait_for_single_object
76 , (abs_time <= cur_time) ? 0u
77 : (abs_time - cur_time).total_milliseconds()
79 if(ret == winapi::wait_object_0){
82 else if(ret == winapi::wait_timeout){
86 error_info err = system_error_code();
87 throw interprocess_exception(err);
91 } //namespace ipcdetail {
92 } //namespace interprocess {
95 #include <boost/interprocess/detail/config_end.hpp>
97 #endif //BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP