Realistic 3D camera system
3D camera system components
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
asio-1.10.6
include
asio
detail
scoped_lock.hpp
Go to the documentation of this file.
1
//
2
// detail/scoped_lock.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~
4
//
5
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6
//
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
//
10
11
#ifndef ASIO_DETAIL_SCOPED_LOCK_HPP
12
#define ASIO_DETAIL_SCOPED_LOCK_HPP
13
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
# pragma once
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18
#include "
asio/detail/noncopyable.hpp
"
19
20
#include "
asio/detail/push_options.hpp
"
21
22
namespace
asio
{
23
namespace
detail {
24
25
// Helper class to lock and unlock a mutex automatically.
26
template
<
typename
Mutex>
27
class
scoped_lock
28
:
private
noncopyable
29
{
30
public
:
31
// Tag type used to distinguish constructors.
32
enum
adopt_lock_t
{
adopt_lock
};
33
34
// Constructor adopts a lock that is already held.
35
scoped_lock
(Mutex& m,
adopt_lock_t
)
36
: mutex_(m),
37
locked_(true)
38
{
39
}
40
41
// Constructor acquires the lock.
42
explicit
scoped_lock
(Mutex& m)
43
: mutex_(m)
44
{
45
mutex_.lock();
46
locked_ =
true
;
47
}
48
49
// Destructor releases the lock.
50
~scoped_lock
()
51
{
52
if
(locked_)
53
mutex_.unlock();
54
}
55
56
// Explicitly acquire the lock.
57
void
lock
()
58
{
59
if
(!locked_)
60
{
61
mutex_.lock();
62
locked_ =
true
;
63
}
64
}
65
66
// Explicitly release the lock.
67
void
unlock
()
68
{
69
if
(locked_)
70
{
71
mutex_.unlock();
72
locked_ =
false
;
73
}
74
}
75
76
// Test whether the lock is held.
77
bool
locked
()
const
78
{
79
return
locked_;
80
}
81
82
// Get the underlying mutex.
83
Mutex&
mutex
()
84
{
85
return
mutex_;
86
}
87
88
private
:
89
// The underlying mutex.
90
Mutex& mutex_;
91
92
// Whether the mutex is currently locked or unlocked.
93
bool
locked_;
94
};
95
96
}
// namespace detail
97
}
// namespace asio
98
99
#include "
asio/detail/pop_options.hpp
"
100
101
#endif // ASIO_DETAIL_SCOPED_LOCK_HPP
asio::detail::scoped_lock::locked
bool locked() const
Definition:
scoped_lock.hpp:77
asio::detail::scoped_lock
Definition:
scoped_lock.hpp:27
asio::detail::scoped_lock::mutex
Mutex & mutex()
Definition:
scoped_lock.hpp:83
asio::detail::noncopyable
Definition:
noncopyable.hpp:25
asio::detail::scoped_lock::scoped_lock
scoped_lock(Mutex &m, adopt_lock_t)
Definition:
scoped_lock.hpp:35
push_options.hpp
asio::detail::scoped_lock::adopt_lock_t
adopt_lock_t
Definition:
scoped_lock.hpp:32
asio::detail::scoped_lock::scoped_lock
scoped_lock(Mutex &m)
Definition:
scoped_lock.hpp:42
asio::detail::scoped_lock::~scoped_lock
~scoped_lock()
Definition:
scoped_lock.hpp:50
asio::detail::scoped_lock::lock
void lock()
Definition:
scoped_lock.hpp:57
asio::detail::scoped_lock::adopt_lock
Definition:
scoped_lock.hpp:32
pop_options.hpp
noncopyable.hpp
asio::detail::scoped_lock::unlock
void unlock()
Definition:
scoped_lock.hpp:67
asio
Definition:
async_result.hpp:23
Generated by
1.8.11