Warning, file /include/boost/thread/strict_lock.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006 #ifndef BOOST_THREAD_STRICT_LOCK_HPP
0007 #define BOOST_THREAD_STRICT_LOCK_HPP
0008
0009 #include <boost/thread/detail/config.hpp>
0010 #include <boost/thread/detail/delete.hpp>
0011 #include <boost/thread/detail/lockable_wrapper.hpp>
0012 #include <boost/thread/lock_options.hpp>
0013 #include <boost/thread/lock_traits.hpp>
0014 #include <boost/thread/lockable_traits.hpp>
0015 #include <boost/thread/lockable_concepts.hpp>
0016 #include <boost/thread/lock_concepts.hpp>
0017 #include <boost/thread/exceptions.hpp>
0018 #include <boost/throw_exception.hpp>
0019
0020 #include <boost/config/abi_prefix.hpp>
0021
0022 namespace boost
0023 {
0024
0025
0026
0027 template <typename Lockable>
0028 class strict_lock
0029 {
0030
0031 BOOST_CONCEPT_ASSERT(( BasicLockable<Lockable> ));
0032 public:
0033 typedef Lockable mutex_type;
0034
0035
0036
0037 BOOST_THREAD_NO_COPYABLE( strict_lock)
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 explicit strict_lock(mutex_type& mtx) :
0048 mtx_(mtx)
0049 {
0050 mtx.lock();
0051 }
0052
0053
0054 #if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
0055 strict_lock(std::initializer_list<thread_detail::lockable_wrapper<Lockable> > l_) :
0056 mtx_(*(const_cast<thread_detail::lockable_wrapper<Lockable>*>(l_.begin())->m))
0057 {
0058 mtx_.lock();
0059 }
0060 #endif
0061
0062
0063
0064
0065
0066
0067
0068
0069 ~strict_lock()
0070 {
0071 mtx_.unlock();
0072 }
0073
0074
0075
0076
0077
0078
0079
0080 mutex_type* mutex() const BOOST_NOEXCEPT
0081 {
0082 return &mtx_;
0083 }
0084
0085
0086
0087
0088 bool owns_lock() const BOOST_NOEXCEPT
0089 {
0090 return true;
0091 }
0092
0093
0094
0095
0096 bool owns_lock(const mutex_type* l) const BOOST_NOEXCEPT
0097 {
0098 return l == mutex();
0099 }
0100
0101
0102
0103
0104
0105
0106 private:
0107 mutex_type& mtx_;
0108 };
0109
0110 template <typename Lockable>
0111 struct is_strict_lock_sur_parole<strict_lock<Lockable> > : true_type
0112 {
0113 };
0114
0115
0116
0117
0118
0119
0120
0121 template <typename Lock>
0122 class nested_strict_lock
0123 {
0124 BOOST_CONCEPT_ASSERT(( BasicLock<Lock> ));
0125 public:
0126 typedef typename Lock::mutex_type mutex_type;
0127
0128 BOOST_THREAD_NO_COPYABLE( nested_strict_lock)
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147 explicit nested_strict_lock(Lock& lk) :
0148 lk_(lk)
0149 {
0150
0151 BOOST_THREAD_ASSERT_PRECONDITION( lk.mutex() != 0,
0152 lock_error()
0153 );
0154 if (!lk.owns_lock()) lk.lock();
0155 tmp_lk_ = move(lk);
0156 }
0157
0158 #if ! defined BOOST_THREAD_NO_CXX11_HDR_INITIALIZER_LIST
0159 nested_strict_lock(std::initializer_list<thread_detail::lockable_wrapper<Lock> > l_) :
0160 lk_(*(const_cast<thread_detail::lockable_wrapper<Lock>*>(l_.begin())->m))
0161 {
0162
0163 BOOST_THREAD_ASSERT_PRECONDITION( lk_.mutex() != 0,
0164 lock_error()
0165 );
0166 if (!lk_.owns_lock()) lk_.lock();
0167 tmp_lk_ = move(lk_);
0168 }
0169 #endif
0170
0171
0172
0173
0174
0175
0176 ~nested_strict_lock()BOOST_NOEXCEPT
0177 {
0178 lk_ = move(tmp_lk_);
0179 }
0180
0181
0182
0183
0184
0185 mutex_type* mutex() const BOOST_NOEXCEPT
0186 {
0187 return tmp_lk_.mutex();
0188 }
0189
0190
0191
0192
0193 bool owns_lock() const BOOST_NOEXCEPT
0194 {
0195 return true;
0196 }
0197
0198
0199
0200
0201 bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT
0202 {
0203 return l == mutex();
0204 }
0205
0206
0207
0208
0209 private:
0210 Lock& lk_;
0211 Lock tmp_lk_;
0212 };
0213
0214
0215 template <typename Lock>
0216 struct is_strict_lock_sur_parole<nested_strict_lock<Lock> > : true_type
0217 {
0218 };
0219
0220 #if ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK
0221 template <typename Lockable>
0222 strict_lock<Lockable> make_strict_lock(Lockable& mtx)
0223 {
0224 return { thread_detail::lockable_wrapper<Lockable>(mtx) };
0225 }
0226 template <typename Lock>
0227 nested_strict_lock<Lock> make_nested_strict_lock(Lock& lk)
0228 {
0229 return { thread_detail::lockable_wrapper<Lock>(lk) };
0230 }
0231 #endif
0232 }
0233 #include <boost/config/abi_suffix.hpp>
0234
0235 #endif