]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/interprocess/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / interprocess / include / boost / interprocess / sync / windows / winapi_wrapper_common.hpp
CommitLineData
7c673cae
FG
1 //////////////////////////////////////////////////////////////////////////////
2//
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)
6//
7// See http://www.boost.org/libs/interprocess for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11#ifndef BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
12#define BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP
13
14#ifndef BOOST_CONFIG_HPP
15# include <boost/config.hpp>
16#endif
17#
18#if defined(BOOST_HAS_PRAGMA_ONCE)
19# pragma once
20#endif
21
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>
28#include <limits>
29
30namespace boost {
31namespace interprocess {
32namespace ipcdetail {
33
34inline void winapi_wrapper_wait_for_single_object(void *handle)
35{
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);
41 }
42 else{ //Special case for orphaned mutexes
43 winapi::release_mutex(handle);
44 throw interprocess_exception(owner_dead_error);
45 }
46 }
47}
48
49inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
50{
51 unsigned long ret = winapi::wait_for_single_object(handle, 0);
52 if(ret == winapi::wait_object_0){
53 return true;
54 }
55 else if(ret == winapi::wait_timeout){
56 return false;
57 }
58 else{
59 error_info err = system_error_code();
60 throw interprocess_exception(err);
61 }
62}
63
64inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time)
65{
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);
69 return true;
70 }
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
75 ( handle
76 , (abs_time <= cur_time) ? 0u
77 : (abs_time - cur_time).total_milliseconds()
78 );
79 if(ret == winapi::wait_object_0){
80 return true;
81 }
82 else if(ret == winapi::wait_timeout){
83 return false;
84 }
85 else{
86 error_info err = system_error_code();
87 throw interprocess_exception(err);
88 }
89}
90
91} //namespace ipcdetail {
92} //namespace interprocess {
93} //namespace boost {
94
95#include <boost/interprocess/detail/config_end.hpp>
96
97#endif //BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP