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 bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time);
36 inline void winapi_wrapper_wait_for_single_object(void *handle)
38 winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::pos_infin);
41 inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
43 return winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::min_date_time);
46 inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time)
48 const boost::posix_time::ptime cur_time = microsec_clock::universal_time();
49 //Windows uses relative wait times so check for negative waits
50 //and implement as 0 wait to allow try-semantics as POSIX mandates.
51 unsigned long time = 0u;
52 if (abs_time == boost::posix_time::pos_infin){
53 time = winapi::infinite_time;
55 else if(abs_time > cur_time){
56 time = (abs_time - cur_time).total_milliseconds();
59 unsigned long ret = winapi::wait_for_single_object(handle, time);
60 if(ret == winapi::wait_object_0){
63 else if(ret == winapi::wait_timeout){
66 else if(ret == winapi::wait_abandoned){ //Special case for orphaned mutexes
67 winapi::release_mutex(handle);
68 throw interprocess_exception(owner_dead_error);
71 error_info err = system_error_code();
72 throw interprocess_exception(err);
76 } //namespace ipcdetail {
77 } //namespace interprocess {
80 #include <boost/interprocess/detail/config_end.hpp>
82 #endif //BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP