]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/interprocess/sync/detail/locks.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / interprocess / sync / detail / locks.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2012-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_LOCKS_HPP
12 #define BOOST_INTERPROCESS_DETAIL_LOCKS_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
25 namespace boost {
26 namespace interprocess {
27 namespace ipcdetail {
28
29 template<class Lock>
30 class internal_mutex_lock
31 {
32 typedef void (internal_mutex_lock::*unspecified_bool_type)();
33 public:
34
35 typedef typename Lock::mutex_type::internal_mutex_type mutex_type;
36
37
38 internal_mutex_lock(Lock &l)
39 : l_(l)
40 {}
41
42 mutex_type* mutex() const
43 { return l_ ? &l_.mutex()->internal_mutex() : 0; }
44
45 void lock() { l_.lock(); }
46
47 void unlock() { l_.unlock(); }
48
49 operator unspecified_bool_type() const
50 { return l_ ? &internal_mutex_lock::lock : 0; }
51
52 private:
53 Lock &l_;
54 };
55
56 template <class Lock>
57 class lock_inverter
58 {
59 Lock &l_;
60 public:
61 lock_inverter(Lock &l)
62 : l_(l)
63 {}
64 void lock() { l_.unlock(); }
65 void unlock() { l_.lock(); }
66 };
67
68 template <class Lock>
69 class lock_to_sharable
70 {
71 Lock &l_;
72
73 public:
74 explicit lock_to_sharable(Lock &l)
75 : l_(l)
76 {}
77 void lock() { l_.lock_sharable(); }
78 bool try_lock(){ return l_.try_lock_sharable(); }
79 void unlock() { l_.unlock_sharable(); }
80 };
81
82 template <class Lock>
83 class lock_to_wait
84 {
85 Lock &l_;
86
87 public:
88 explicit lock_to_wait(Lock &l)
89 : l_(l)
90 {}
91 void lock() { l_.wait(); }
92 bool try_lock(){ return l_.try_wait(); }
93 };
94
95 } //namespace ipcdetail
96 } //namespace interprocess
97 } //namespace boost
98
99 #include <boost/interprocess/detail/config_end.hpp>
100
101 #endif //BOOST_INTERPROCESS_DETAIL_LOCKS_HPP