Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 08:50:20

0001  //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 #include <boost/interprocess/detail/win32_api.hpp>
0026 #include <boost/interprocess/errors.hpp>
0027 #include <boost/interprocess/exceptions.hpp>
0028 #include <boost/interprocess/timed_utils.hpp>
0029 #include <limits>
0030 
0031 namespace boost {
0032 namespace interprocess {
0033 namespace ipcdetail {
0034 
0035 inline bool do_winapi_wait(void *handle, unsigned long dwMilliseconds)
0036 {
0037    unsigned long ret = winapi::wait_for_single_object(handle, dwMilliseconds);
0038    if(ret == winapi::wait_object_0){
0039       return true;
0040    }
0041    else if(ret == winapi::wait_timeout){
0042       return false;
0043    }
0044    else if(ret == winapi::wait_abandoned){ //Special case for orphaned mutexes
0045       winapi::release_mutex(handle);
0046       throw interprocess_exception(owner_dead_error);
0047    }
0048    else{
0049       error_info err = system_error_code();
0050       throw interprocess_exception(err);
0051    }
0052 }
0053 
0054 template<class TimePoint>
0055 inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const TimePoint &abs_time)
0056 {
0057    //Windows uses relative wait times so check for negative waits
0058    //and implement as 0 wait to allow try-semantics as POSIX mandates.
0059    unsigned long time_ms = 0u;
0060    if (ipcdetail::is_pos_infinity(abs_time)){
0061       time_ms = winapi::infinite_time;
0062    }
0063    else {
0064       typedef typename microsec_clock<TimePoint>::time_point time_point;
0065       const time_point cur_time = microsec_clock<TimePoint>::universal_time();
0066       if(abs_time > cur_time){
0067          time_ms = static_cast<unsigned long>(duration_to_milliseconds(abs_time - cur_time));
0068       }
0069    }
0070    return do_winapi_wait(handle, time_ms);
0071 }
0072 
0073 inline void winapi_wrapper_wait_for_single_object(void *handle)
0074 {
0075    (void)do_winapi_wait(handle, winapi::infinite_time);
0076 }
0077 
0078 inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
0079 {
0080    return do_winapi_wait(handle, 0u);
0081 }
0082 
0083 }  //namespace ipcdetail {
0084 }  //namespace interprocess {
0085 }  //namespace boost {
0086 
0087 #include <boost/interprocess/detail/config_end.hpp>
0088 
0089 #endif   //BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP