]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/interprocess/sync/windows/mutex.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / interprocess / sync / windows / mutex.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-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_WINDOWS_MUTEX_HPP
12 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_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/windows_intermodule_singleton.hpp>
26 #include <boost/interprocess/sync/windows/sync_utils.hpp>
27 #include <boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp>
28 #include <boost/interprocess/exceptions.hpp>
29
30
31 namespace boost {
32 namespace interprocess {
33 namespace ipcdetail {
34
35 class winapi_mutex
36 {
37 winapi_mutex(const winapi_mutex &);
38 winapi_mutex &operator=(const winapi_mutex &);
39 public:
40
41 winapi_mutex();
42 ~winapi_mutex();
43
44 void lock();
45 bool try_lock();
46 template<class TimePoint> bool timed_lock(const TimePoint &abs_time);
47
48 template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
49 { return this->timed_lock(abs_time); }
50
51 template<class Duration> bool try_lock_for(const Duration &dur)
52 { return this->timed_lock(duration_to_ustime(dur)); }
53
54 void unlock();
55 void take_ownership(){};
56
57 private:
58 const sync_id id_;
59 };
60
61 inline winapi_mutex::winapi_mutex()
62 : id_()
63 {
64 sync_handles &handles =
65 windows_intermodule_singleton<sync_handles>::get();
66 //Create mutex with the initial count
67 bool open_or_created;
68 (void)handles.obtain_mutex(this->id_, this, &open_or_created);
69 //The mutex must be created, never opened
70 BOOST_ASSERT(open_or_created);
71 BOOST_ASSERT(open_or_created && winapi::get_last_error() != winapi::error_already_exists);
72 (void)open_or_created;
73 }
74
75 inline winapi_mutex::~winapi_mutex()
76 {
77 sync_handles &handles =
78 windows_intermodule_singleton<sync_handles>::get();
79 handles.destroy_handle(this->id_, this);
80 }
81
82 inline void winapi_mutex::lock(void)
83 {
84 sync_handles &handles =
85 windows_intermodule_singleton<sync_handles>::get();
86 //This can throw
87 winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
88 mut.lock();
89 }
90
91 inline bool winapi_mutex::try_lock(void)
92 {
93 sync_handles &handles =
94 windows_intermodule_singleton<sync_handles>::get();
95 //This can throw
96 winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
97 return mut.try_lock();
98 }
99
100 template<class TimePoint>
101 inline bool winapi_mutex::timed_lock(const TimePoint &abs_time)
102 {
103 sync_handles &handles =
104 windows_intermodule_singleton<sync_handles>::get();
105 //This can throw
106 winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
107 return mut.timed_lock(abs_time);
108 }
109
110 inline void winapi_mutex::unlock(void)
111 {
112 sync_handles &handles =
113 windows_intermodule_singleton<sync_handles>::get();
114 //This can throw
115 winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
116 return mut.unlock();
117 }
118
119 } //namespace ipcdetail {
120 } //namespace interprocess {
121 } //namespace boost {
122
123 #include <boost/interprocess/detail/config_end.hpp>
124
125 #endif //BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP