Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:32

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 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024 #include <boost/interprocess/detail/win32_api.hpp>
0025 #include <boost/interprocess/errors.hpp>
0026 #include <boost/interprocess/exceptions.hpp>
0027 #include <boost/interprocess/detail/timed_utils.hpp>
0028 #include <limits>
0029 
0030 namespace boost {
0031 namespace interprocess {
0032 namespace ipcdetail {
0033 
0034 inline bool do_winapi_wait(void *handle, unsigned long dwMilliseconds)
0035 {
0036    unsigned long ret = winapi::wait_for_single_object(handle, dwMilliseconds);
0037    if(ret == winapi::wait_object_0){
0038       return true;
0039    }
0040    else if(ret == winapi::wait_timeout){
0041       return false;
0042    }
0043    else if(ret == winapi::wait_abandoned){ //Special case for orphaned mutexes
0044       winapi::release_mutex(handle);
0045       throw interprocess_exception(owner_dead_error);
0046    }
0047    else{
0048       error_info err = system_error_code();
0049       throw interprocess_exception(err);
0050    }
0051 }
0052 
0053 template<class TimePoint>
0054 inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const TimePoint &abs_time)
0055 {
0056    //Windows uses relative wait times so check for negative waits
0057    //and implement as 0 wait to allow try-semantics as POSIX mandates.
0058    unsigned long time_ms = 0u;
0059    if (ipcdetail::is_pos_infinity(abs_time)){
0060       time_ms = winapi::infinite_time;
0061    }
0062    else {
0063       const TimePoint cur_time = microsec_clock<TimePoint>::universal_time();
0064       if(abs_time > cur_time){
0065          time_ms = static_cast<unsigned long>(duration_to_milliseconds(abs_time - cur_time));
0066       }
0067    }
0068    return do_winapi_wait(handle, time_ms);
0069 }
0070 
0071 inline void winapi_wrapper_wait_for_single_object(void *handle)
0072 {
0073    (void)do_winapi_wait(handle, winapi::infinite_time);
0074 }
0075 
0076 inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
0077 {
0078    return do_winapi_wait(handle, 0u);
0079 }
0080 
0081 }  //namespace ipcdetail {
0082 }  //namespace interprocess {
0083 }  //namespace boost {
0084 
0085 #include <boost/interprocess/detail/config_end.hpp>
0086 
0087 #endif   //BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP