]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/interprocess/sync/windows/winapi_wrapper_common.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / 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
92f5a8d4
TL
34inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time);
35
7c673cae
FG
36inline void winapi_wrapper_wait_for_single_object(void *handle)
37{
92f5a8d4 38 winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::pos_infin);
7c673cae
FG
39}
40
41inline bool winapi_wrapper_try_wait_for_single_object(void *handle)
42{
92f5a8d4 43 return winapi_wrapper_timed_wait_for_single_object(handle, boost::posix_time::min_date_time);
7c673cae
FG
44}
45
46inline bool winapi_wrapper_timed_wait_for_single_object(void *handle, const boost::posix_time::ptime &abs_time)
47{
7c673cae
FG
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.
92f5a8d4
TL
51 unsigned long time = 0u;
52 if (abs_time == boost::posix_time::pos_infin){
53 time = winapi::infinite_time;
54 }
55 else if(abs_time > cur_time){
56 time = (abs_time - cur_time).total_milliseconds();
57 }
58
59 unsigned long ret = winapi::wait_for_single_object(handle, time);
7c673cae
FG
60 if(ret == winapi::wait_object_0){
61 return true;
62 }
63 else if(ret == winapi::wait_timeout){
64 return false;
65 }
92f5a8d4
TL
66 else if(ret == winapi::wait_abandoned){ //Special case for orphaned mutexes
67 winapi::release_mutex(handle);
68 throw interprocess_exception(owner_dead_error);
69 }
7c673cae
FG
70 else{
71 error_info err = system_error_code();
72 throw interprocess_exception(err);
73 }
74}
75
76} //namespace ipcdetail {
77} //namespace interprocess {
78} //namespace boost {
79
80#include <boost/interprocess/detail/config_end.hpp>
81
92f5a8d4 82#endif //BOOST_INTERPROCESS_DETAIL_WINAPI_WRAPPER_COMMON_HPP