blob: 88d9c0cb48772f617857be3f4bb3d3e523a44528 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2012-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
#define BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
namespace boost {
namespace interprocess {
namespace ipcdetail {
template<class Lock>
class internal_mutex_lock
{
typedef void (internal_mutex_lock::*unspecified_bool_type)();
public:
typedef typename Lock::mutex_type::internal_mutex_type mutex_type;
internal_mutex_lock(Lock &l)
: l_(l)
{}
mutex_type* mutex() const
{ return l_ ? &l_.mutex()->internal_mutex() : 0; }
void lock() { l_.lock(); }
void unlock() { l_.unlock(); }
operator unspecified_bool_type() const
{ return l_ ? &internal_mutex_lock::lock : 0; }
private:
Lock &l_;
};
template <class Lock>
class lock_inverter
{
Lock &l_;
public:
lock_inverter(Lock &l)
: l_(l)
{}
void lock() { l_.unlock(); }
void unlock() { l_.lock(); }
};
template <class Lock>
class lock_to_sharable
{
Lock &l_;
public:
explicit lock_to_sharable(Lock &l)
: l_(l)
{}
void lock() { l_.lock_sharable(); }
bool try_lock(){ return l_.try_lock_sharable(); }
void unlock() { l_.unlock_sharable(); }
};
template <class Lock>
class lock_to_wait
{
Lock &l_;
public:
explicit lock_to_wait(Lock &l)
: l_(l)
{}
void lock() { l_.wait(); }
bool try_lock(){ return l_.try_wait(); }
};
} //namespace ipcdetail
} //namespace interprocess
} //namespace boost
#include <boost/interprocess/detail/config_end.hpp>
#endif //BOOST_INTERPROCESS_DETAIL_LOCKS_HPP
|