lock_types.hpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. // Distributed under the Boost Software License, Version 1.0. (See
  2. // accompanying file LICENSE_1_0.txt or copy at
  3. // http://www.boost.org/LICENSE_1_0.txt)
  4. // (C) Copyright 2007 Anthony Williams
  5. // (C) Copyright 2011-2012 Vicente J. Botet Escriba
  6. #ifndef BOOST_THREAD_LOCK_TYPES_HPP
  7. #define BOOST_THREAD_LOCK_TYPES_HPP
  8. #include <boost/thread/detail/config.hpp>
  9. #include <boost/thread/detail/move.hpp>
  10. #include <boost/thread/exceptions.hpp>
  11. #include <boost/thread/lock_options.hpp>
  12. #include <boost/thread/lockable_traits.hpp>
  13. #if ! defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
  14. #include <boost/thread/is_locked_by_this_thread.hpp>
  15. #endif
  16. #include <boost/thread/thread_time.hpp>
  17. #include <boost/assert.hpp>
  18. #ifdef BOOST_THREAD_USES_CHRONO
  19. #include <boost/chrono/time_point.hpp>
  20. #include <boost/chrono/duration.hpp>
  21. #endif
  22. #include <boost/detail/workaround.hpp>
  23. #include <boost/config/abi_prefix.hpp>
  24. namespace boost
  25. {
  26. struct xtime;
  27. template <typename Mutex>
  28. class shared_lock;
  29. template <typename Mutex>
  30. class upgrade_lock;
  31. template <typename Mutex>
  32. class unique_lock;
  33. namespace detail
  34. {
  35. template <typename Mutex>
  36. class try_lock_wrapper;
  37. }
  38. #ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
  39. namespace sync
  40. {
  41. template<typename T>
  42. struct is_basic_lockable<unique_lock<T> >
  43. {
  44. BOOST_STATIC_CONSTANT(bool, value = true);
  45. };
  46. template<typename T>
  47. struct is_lockable<unique_lock<T> >
  48. {
  49. BOOST_STATIC_CONSTANT(bool, value = true);
  50. };
  51. template<typename T>
  52. struct is_basic_lockable<shared_lock<T> >
  53. {
  54. BOOST_STATIC_CONSTANT(bool, value = true);
  55. };
  56. template<typename T>
  57. struct is_lockable<shared_lock<T> >
  58. {
  59. BOOST_STATIC_CONSTANT(bool, value = true);
  60. };
  61. template<typename T>
  62. struct is_basic_lockable<upgrade_lock<T> >
  63. {
  64. BOOST_STATIC_CONSTANT(bool, value = true);
  65. };
  66. template<typename T>
  67. struct is_lockable<upgrade_lock<T> >
  68. {
  69. BOOST_STATIC_CONSTANT(bool, value = true);
  70. };
  71. template<typename T>
  72. struct is_basic_lockable<detail::try_lock_wrapper<T> >
  73. {
  74. BOOST_STATIC_CONSTANT(bool, value = true);
  75. };
  76. template<typename T>
  77. struct is_lockable<detail::try_lock_wrapper<T> >
  78. {
  79. BOOST_STATIC_CONSTANT(bool, value = true);
  80. };
  81. }
  82. #endif
  83. template <typename Mutex>
  84. class unique_lock
  85. {
  86. private:
  87. Mutex* m;
  88. bool is_locked;
  89. private:
  90. explicit unique_lock(upgrade_lock<Mutex>&);
  91. unique_lock& operator=(upgrade_lock<Mutex>& other);
  92. public:
  93. typedef Mutex mutex_type;
  94. BOOST_THREAD_MOVABLE_ONLY( unique_lock)
  95. #if 0 // This should not be needed anymore. Use instead BOOST_THREAD_MAKE_RV_REF.
  96. #if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
  97. unique_lock(const volatile unique_lock&);
  98. #endif
  99. #endif
  100. unique_lock()BOOST_NOEXCEPT :
  101. m(0),is_locked(false)
  102. {}
  103. explicit unique_lock(Mutex& m_) :
  104. m(&m_), is_locked(false)
  105. {
  106. lock();
  107. }
  108. unique_lock(Mutex& m_, adopt_lock_t) :
  109. m(&m_), is_locked(true)
  110. {
  111. #if ! defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
  112. BOOST_ASSERT(is_locked_by_this_thread(m));
  113. #endif
  114. }
  115. unique_lock(Mutex& m_, defer_lock_t)BOOST_NOEXCEPT:
  116. m(&m_),is_locked(false)
  117. {}
  118. unique_lock(Mutex& m_, try_to_lock_t) :
  119. m(&m_), is_locked(false)
  120. {
  121. try_lock();
  122. }
  123. #if defined BOOST_THREAD_USES_DATETIME
  124. template<typename TimeDuration>
  125. unique_lock(Mutex& m_,TimeDuration const& target_time):
  126. m(&m_),is_locked(false)
  127. {
  128. timed_lock(target_time);
  129. }
  130. unique_lock(Mutex& m_,system_time const& target_time):
  131. m(&m_),is_locked(false)
  132. {
  133. timed_lock(target_time);
  134. }
  135. #endif
  136. #ifdef BOOST_THREAD_USES_CHRONO
  137. template <class Clock, class Duration>
  138. unique_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t)
  139. : m(&mtx), is_locked(mtx.try_lock_until(t))
  140. {
  141. }
  142. template <class Rep, class Period>
  143. unique_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d)
  144. : m(&mtx), is_locked(mtx.try_lock_for(d))
  145. {
  146. }
  147. #endif
  148. unique_lock(BOOST_THREAD_RV_REF(unique_lock) other) BOOST_NOEXCEPT:
  149. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  150. {
  151. BOOST_THREAD_RV(other).is_locked=false;
  152. BOOST_THREAD_RV(other).m=0;
  153. }
  154. BOOST_THREAD_EXPLICIT_LOCK_CONVERSION unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other);
  155. #ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
  156. //std-2104 unique_lock move-assignment should not be noexcept
  157. unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
  158. {
  159. unique_lock temp(::boost::move(other));
  160. swap(temp);
  161. return *this;
  162. }
  163. #endif
  164. //std-2104 unique_lock move-assignment should not be noexcept
  165. unique_lock& operator=(BOOST_THREAD_RV_REF(unique_lock) other) //BOOST_NOEXCEPT
  166. {
  167. unique_lock temp(::boost::move(other));
  168. swap(temp);
  169. return *this;
  170. }
  171. #if 0 // This should not be needed anymore. Use instead BOOST_THREAD_MAKE_RV_REF.
  172. #if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
  173. unique_lock& operator=(unique_lock<Mutex> other)
  174. {
  175. swap(other);
  176. return *this;
  177. }
  178. #endif // BOOST_WORKAROUND
  179. #endif
  180. // Conversion from upgrade locking
  181. unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<mutex_type> BOOST_THREAD_RV_REF_END ul, try_to_lock_t)
  182. : m(0),is_locked(false)
  183. {
  184. if (BOOST_THREAD_RV(ul).owns_lock())
  185. {
  186. if (BOOST_THREAD_RV(ul).mutex()->try_unlock_upgrade_and_lock())
  187. {
  188. m = BOOST_THREAD_RV(ul).release();
  189. is_locked = true;
  190. }
  191. }
  192. else
  193. {
  194. m = BOOST_THREAD_RV(ul).release();
  195. }
  196. }
  197. #ifdef BOOST_THREAD_USES_CHRONO
  198. template <class Clock, class Duration>
  199. unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<mutex_type> BOOST_THREAD_RV_REF_END ul,
  200. const chrono::time_point<Clock, Duration>& abs_time)
  201. : m(0),is_locked(false)
  202. {
  203. if (BOOST_THREAD_RV(ul).owns_lock())
  204. {
  205. if (BOOST_THREAD_RV(ul).mutex()->try_unlock_upgrade_and_lock_until(abs_time))
  206. {
  207. m = BOOST_THREAD_RV(ul).release();
  208. is_locked = true;
  209. }
  210. }
  211. else
  212. {
  213. m = BOOST_THREAD_RV(ul).release();
  214. }
  215. }
  216. template <class Rep, class Period>
  217. unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<mutex_type> BOOST_THREAD_RV_REF_END ul,
  218. const chrono::duration<Rep, Period>& rel_time)
  219. : m(0),is_locked(false)
  220. {
  221. if (BOOST_THREAD_RV(ul).owns_lock())
  222. {
  223. if (BOOST_THREAD_RV(ul).mutex()->try_unlock_upgrade_and_lock_for(rel_time))
  224. {
  225. m = BOOST_THREAD_RV(ul).release();
  226. is_locked = true;
  227. }
  228. }
  229. else
  230. {
  231. m = BOOST_THREAD_RV(ul).release();
  232. }
  233. }
  234. #endif
  235. #ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
  236. // Conversion from shared locking
  237. unique_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, try_to_lock_t)
  238. : m(0),is_locked(false)
  239. {
  240. if (BOOST_THREAD_RV(sl).owns_lock())
  241. {
  242. if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock())
  243. {
  244. m = BOOST_THREAD_RV(sl).release();
  245. is_locked = true;
  246. }
  247. }
  248. else
  249. {
  250. m = BOOST_THREAD_RV(sl).release();
  251. }
  252. }
  253. #ifdef BOOST_THREAD_USES_CHRONO
  254. template <class Clock, class Duration>
  255. unique_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl,
  256. const chrono::time_point<Clock, Duration>& abs_time)
  257. : m(0),is_locked(false)
  258. {
  259. if (BOOST_THREAD_RV(sl).owns_lock())
  260. {
  261. if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_until(abs_time))
  262. {
  263. m = BOOST_THREAD_RV(sl).release();
  264. is_locked = true;
  265. }
  266. }
  267. else
  268. {
  269. m = BOOST_THREAD_RV(sl).release();
  270. }
  271. }
  272. template <class Rep, class Period>
  273. unique_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl,
  274. const chrono::duration<Rep, Period>& rel_time)
  275. : m(0),is_locked(false)
  276. {
  277. if (BOOST_THREAD_RV(sl).owns_lock())
  278. {
  279. if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_for(rel_time))
  280. {
  281. m = BOOST_THREAD_RV(sl).release();
  282. is_locked = true;
  283. }
  284. }
  285. else
  286. {
  287. m = BOOST_THREAD_RV(sl).release();
  288. }
  289. }
  290. #endif // BOOST_THREAD_USES_CHRONO
  291. #endif // BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
  292. void swap(unique_lock& other)BOOST_NOEXCEPT
  293. {
  294. std::swap(m,other.m);
  295. std::swap(is_locked,other.is_locked);
  296. }
  297. ~unique_lock()
  298. {
  299. if (owns_lock())
  300. {
  301. m->unlock();
  302. }
  303. }
  304. void lock()
  305. {
  306. if (m == 0)
  307. {
  308. boost::throw_exception(
  309. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  310. }
  311. if (owns_lock())
  312. {
  313. boost::throw_exception(
  314. boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  315. }
  316. m->lock();
  317. is_locked = true;
  318. }
  319. bool try_lock()
  320. {
  321. if (m == 0)
  322. {
  323. boost::throw_exception(
  324. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  325. }
  326. if (owns_lock())
  327. {
  328. boost::throw_exception(
  329. boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  330. }
  331. is_locked = m->try_lock();
  332. return is_locked;
  333. }
  334. #if defined BOOST_THREAD_USES_DATETIME
  335. template<typename TimeDuration>
  336. bool timed_lock(TimeDuration const& relative_time)
  337. {
  338. if(m==0)
  339. {
  340. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  341. }
  342. if(owns_lock())
  343. {
  344. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  345. }
  346. is_locked=m->timed_lock(relative_time);
  347. return is_locked;
  348. }
  349. bool timed_lock(::boost::system_time const& absolute_time)
  350. {
  351. if(m==0)
  352. {
  353. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  354. }
  355. if(owns_lock())
  356. {
  357. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  358. }
  359. is_locked=m->timed_lock(absolute_time);
  360. return is_locked;
  361. }
  362. bool timed_lock(::boost::xtime const& absolute_time)
  363. {
  364. if(m==0)
  365. {
  366. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  367. }
  368. if(owns_lock())
  369. {
  370. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  371. }
  372. is_locked=m->timed_lock(absolute_time);
  373. return is_locked;
  374. }
  375. #endif
  376. #ifdef BOOST_THREAD_USES_CHRONO
  377. template <class Rep, class Period>
  378. bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
  379. {
  380. if(m==0)
  381. {
  382. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  383. }
  384. if(owns_lock())
  385. {
  386. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  387. }
  388. is_locked=m->try_lock_for(rel_time);
  389. return is_locked;
  390. }
  391. template <class Clock, class Duration>
  392. bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
  393. {
  394. if(m==0)
  395. {
  396. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  397. }
  398. if(owns_lock())
  399. {
  400. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost unique_lock owns already the mutex"));
  401. }
  402. is_locked=m->try_lock_until(abs_time);
  403. return is_locked;
  404. }
  405. #endif
  406. void unlock()
  407. {
  408. if (m == 0)
  409. {
  410. boost::throw_exception(
  411. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock has no mutex"));
  412. }
  413. if (!owns_lock())
  414. {
  415. boost::throw_exception(
  416. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost unique_lock doesn't own the mutex"));
  417. }
  418. m->unlock();
  419. is_locked = false;
  420. }
  421. #if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  422. typedef void (unique_lock::*bool_type)();
  423. operator bool_type() const BOOST_NOEXCEPT
  424. {
  425. return is_locked?&unique_lock::lock:0;
  426. }
  427. bool operator!() const BOOST_NOEXCEPT
  428. {
  429. return !owns_lock();
  430. }
  431. #else
  432. explicit operator bool() const BOOST_NOEXCEPT
  433. {
  434. return owns_lock();
  435. }
  436. #endif
  437. bool owns_lock() const BOOST_NOEXCEPT
  438. {
  439. return is_locked;
  440. }
  441. Mutex* mutex() const BOOST_NOEXCEPT
  442. {
  443. return m;
  444. }
  445. Mutex* release()BOOST_NOEXCEPT
  446. {
  447. Mutex* const res=m;
  448. m=0;
  449. is_locked=false;
  450. return res;
  451. }
  452. friend class shared_lock<Mutex> ;
  453. friend class upgrade_lock<Mutex> ;
  454. };
  455. template<typename Mutex>
  456. void swap(unique_lock<Mutex>& lhs, unique_lock<Mutex>& rhs)
  457. BOOST_NOEXCEPT
  458. {
  459. lhs.swap(rhs);
  460. }
  461. BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) unique_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END
  462. template<typename Mutex>
  463. class shared_lock
  464. {
  465. protected:
  466. Mutex* m;
  467. bool is_locked;
  468. public:
  469. typedef Mutex mutex_type;
  470. BOOST_THREAD_MOVABLE_ONLY(shared_lock)
  471. shared_lock() BOOST_NOEXCEPT:
  472. m(0),is_locked(false)
  473. {}
  474. explicit shared_lock(Mutex& m_):
  475. m(&m_),is_locked(false)
  476. {
  477. lock();
  478. }
  479. shared_lock(Mutex& m_,adopt_lock_t):
  480. m(&m_),is_locked(true)
  481. {
  482. #if ! defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
  483. BOOST_ASSERT(is_locked_by_this_thread(m));
  484. #endif
  485. }
  486. shared_lock(Mutex& m_,defer_lock_t) BOOST_NOEXCEPT:
  487. m(&m_),is_locked(false)
  488. {}
  489. shared_lock(Mutex& m_,try_to_lock_t):
  490. m(&m_),is_locked(false)
  491. {
  492. try_lock();
  493. }
  494. #if defined BOOST_THREAD_USES_DATETIME
  495. shared_lock(Mutex& m_,system_time const& target_time):
  496. m(&m_),is_locked(false)
  497. {
  498. timed_lock(target_time);
  499. }
  500. #endif
  501. #ifdef BOOST_THREAD_USES_CHRONO
  502. template <class Clock, class Duration>
  503. shared_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t)
  504. : m(&mtx), is_locked(mtx.try_lock_shared_until(t))
  505. {
  506. }
  507. template <class Rep, class Period>
  508. shared_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d)
  509. : m(&mtx), is_locked(mtx.try_lock_shared_for(d))
  510. {
  511. }
  512. #endif
  513. shared_lock(BOOST_THREAD_RV_REF_BEG shared_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT:
  514. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  515. {
  516. BOOST_THREAD_RV(other).is_locked=false;
  517. BOOST_THREAD_RV(other).m=0;
  518. }
  519. BOOST_THREAD_EXPLICIT_LOCK_CONVERSION shared_lock(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other):
  520. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  521. {
  522. if(is_locked)
  523. {
  524. m->unlock_and_lock_shared();
  525. }
  526. BOOST_THREAD_RV(other).is_locked=false;
  527. BOOST_THREAD_RV(other).m=0;
  528. }
  529. BOOST_THREAD_EXPLICIT_LOCK_CONVERSION shared_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other):
  530. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  531. {
  532. if(is_locked)
  533. {
  534. m->unlock_upgrade_and_lock_shared();
  535. }
  536. BOOST_THREAD_RV(other).is_locked=false;
  537. BOOST_THREAD_RV(other).m=0;
  538. }
  539. //std-2104 unique_lock move-assignment should not be noexcept
  540. shared_lock& operator=(BOOST_THREAD_RV_REF_BEG shared_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
  541. {
  542. shared_lock temp(::boost::move(other));
  543. swap(temp);
  544. return *this;
  545. }
  546. #ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
  547. shared_lock& operator=(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other)
  548. {
  549. shared_lock temp(::boost::move(other));
  550. swap(temp);
  551. return *this;
  552. }
  553. shared_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other)
  554. {
  555. shared_lock temp(::boost::move(other));
  556. swap(temp);
  557. return *this;
  558. }
  559. #endif
  560. void swap(shared_lock& other) BOOST_NOEXCEPT
  561. {
  562. std::swap(m,other.m);
  563. std::swap(is_locked,other.is_locked);
  564. }
  565. Mutex* mutex() const BOOST_NOEXCEPT
  566. {
  567. return m;
  568. }
  569. Mutex* release() BOOST_NOEXCEPT
  570. {
  571. Mutex* const res=m;
  572. m=0;
  573. is_locked=false;
  574. return res;
  575. }
  576. ~shared_lock()
  577. {
  578. if(owns_lock())
  579. {
  580. m->unlock_shared();
  581. }
  582. }
  583. void lock()
  584. {
  585. if(m==0)
  586. {
  587. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  588. }
  589. if(owns_lock())
  590. {
  591. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost shared_lock owns already the mutex"));
  592. }
  593. m->lock_shared();
  594. is_locked=true;
  595. }
  596. bool try_lock()
  597. {
  598. if(m==0)
  599. {
  600. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  601. }
  602. if(owns_lock())
  603. {
  604. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost shared_lock owns already the mutex"));
  605. }
  606. is_locked=m->try_lock_shared();
  607. return is_locked;
  608. }
  609. #if defined BOOST_THREAD_USES_DATETIME
  610. bool timed_lock(boost::system_time const& target_time)
  611. {
  612. if(m==0)
  613. {
  614. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  615. }
  616. if(owns_lock())
  617. {
  618. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost shared_lock owns already the mutex"));
  619. }
  620. is_locked=m->timed_lock_shared(target_time);
  621. return is_locked;
  622. }
  623. template<typename Duration>
  624. bool timed_lock(Duration const& target_time)
  625. {
  626. if(m==0)
  627. {
  628. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  629. }
  630. if(owns_lock())
  631. {
  632. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost shared_lock owns already the mutex"));
  633. }
  634. is_locked=m->timed_lock_shared(target_time);
  635. return is_locked;
  636. }
  637. #endif
  638. #ifdef BOOST_THREAD_USES_CHRONO
  639. template <class Rep, class Period>
  640. bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
  641. {
  642. if(m==0)
  643. {
  644. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  645. }
  646. if(owns_lock())
  647. {
  648. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost shared_lock owns already the mutex"));
  649. }
  650. is_locked=m->try_lock_shared_for(rel_time);
  651. return is_locked;
  652. }
  653. template <class Clock, class Duration>
  654. bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
  655. {
  656. if(m==0)
  657. {
  658. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  659. }
  660. if(owns_lock())
  661. {
  662. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost shared_lock owns already the mutex"));
  663. }
  664. is_locked=m->try_lock_shared_until(abs_time);
  665. return is_locked;
  666. }
  667. #endif
  668. void unlock()
  669. {
  670. if(m==0)
  671. {
  672. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock has no mutex"));
  673. }
  674. if(!owns_lock())
  675. {
  676. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost shared_lock doesn't own the mutex"));
  677. }
  678. m->unlock_shared();
  679. is_locked=false;
  680. }
  681. #if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  682. typedef void (shared_lock<Mutex>::*bool_type)();
  683. operator bool_type() const BOOST_NOEXCEPT
  684. {
  685. return is_locked?&shared_lock::lock:0;
  686. }
  687. bool operator!() const BOOST_NOEXCEPT
  688. {
  689. return !owns_lock();
  690. }
  691. #else
  692. explicit operator bool() const BOOST_NOEXCEPT
  693. {
  694. return owns_lock();
  695. }
  696. #endif
  697. bool owns_lock() const BOOST_NOEXCEPT
  698. {
  699. return is_locked;
  700. }
  701. };
  702. BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) shared_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END
  703. template<typename Mutex>
  704. void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs) BOOST_NOEXCEPT
  705. {
  706. lhs.swap(rhs);
  707. }
  708. template <typename Mutex>
  709. class upgrade_lock
  710. {
  711. protected:
  712. Mutex* m;
  713. bool is_locked;
  714. public:
  715. typedef Mutex mutex_type;
  716. BOOST_THREAD_MOVABLE_ONLY( upgrade_lock)
  717. upgrade_lock()BOOST_NOEXCEPT:
  718. m(0),is_locked(false)
  719. {}
  720. explicit upgrade_lock(Mutex& m_) :
  721. m(&m_), is_locked(false)
  722. {
  723. lock();
  724. }
  725. upgrade_lock(Mutex& m_, adopt_lock_t) :
  726. m(&m_), is_locked(true)
  727. {
  728. #if ! defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
  729. BOOST_ASSERT(is_locked_by_this_thread(m));
  730. #endif
  731. }
  732. upgrade_lock(Mutex& m_, defer_lock_t)BOOST_NOEXCEPT:
  733. m(&m_),is_locked(false)
  734. {}
  735. upgrade_lock(Mutex& m_, try_to_lock_t) :
  736. m(&m_), is_locked(false)
  737. {
  738. try_lock();
  739. }
  740. #ifdef BOOST_THREAD_USES_CHRONO
  741. template <class Clock, class Duration>
  742. upgrade_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t)
  743. : m(&mtx), is_locked(mtx.try_lock_upgrade_until(t))
  744. {
  745. }
  746. template <class Rep, class Period>
  747. upgrade_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d)
  748. : m(&mtx), is_locked(mtx.try_lock_upgrade_for(d))
  749. {
  750. }
  751. #endif
  752. upgrade_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT:
  753. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  754. {
  755. BOOST_THREAD_RV(other).is_locked=false;
  756. BOOST_THREAD_RV(other).m=0;
  757. }
  758. BOOST_THREAD_EXPLICIT_LOCK_CONVERSION upgrade_lock(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other):
  759. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  760. {
  761. if(is_locked)
  762. {
  763. m->unlock_and_lock_upgrade();
  764. }
  765. BOOST_THREAD_RV(other).is_locked=false;
  766. BOOST_THREAD_RV(other).m=0;
  767. }
  768. //std-2104 unique_lock move-assignment should not be noexcept
  769. upgrade_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
  770. {
  771. upgrade_lock temp(::boost::move(other));
  772. swap(temp);
  773. return *this;
  774. }
  775. #ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
  776. upgrade_lock& operator=(BOOST_THREAD_RV_REF_BEG unique_lock<Mutex> BOOST_THREAD_RV_REF_END other)
  777. {
  778. upgrade_lock temp(::boost::move(other));
  779. swap(temp);
  780. return *this;
  781. }
  782. #endif
  783. #ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
  784. // Conversion from shared locking
  785. upgrade_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl, try_to_lock_t)
  786. : m(0),is_locked(false)
  787. {
  788. if (BOOST_THREAD_RV(sl).owns_lock())
  789. {
  790. if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_upgrade())
  791. {
  792. m = BOOST_THREAD_RV(sl).release();
  793. is_locked = true;
  794. }
  795. }
  796. else
  797. {
  798. m = BOOST_THREAD_RV(sl).release();
  799. }
  800. }
  801. #ifdef BOOST_THREAD_USES_CHRONO
  802. template <class Clock, class Duration>
  803. upgrade_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl,
  804. const chrono::time_point<Clock, Duration>& abs_time)
  805. : m(0),is_locked(false)
  806. {
  807. if (BOOST_THREAD_RV(sl).owns_lock())
  808. {
  809. if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_upgrade_until(abs_time))
  810. {
  811. m = BOOST_THREAD_RV(sl).release();
  812. is_locked = true;
  813. }
  814. }
  815. else
  816. {
  817. m = BOOST_THREAD_RV(sl).release();
  818. }
  819. }
  820. template <class Rep, class Period>
  821. upgrade_lock(BOOST_THREAD_RV_REF_BEG shared_lock<mutex_type> BOOST_THREAD_RV_REF_END sl,
  822. const chrono::duration<Rep, Period>& rel_time)
  823. : m(0),is_locked(false)
  824. {
  825. if (BOOST_THREAD_RV(sl).owns_lock())
  826. {
  827. if (BOOST_THREAD_RV(sl).mutex()->try_unlock_shared_and_lock_upgrade_for(rel_time))
  828. {
  829. m = BOOST_THREAD_RV(sl).release();
  830. is_locked = true;
  831. }
  832. }
  833. else
  834. {
  835. m = BOOST_THREAD_RV(sl).release();
  836. }
  837. }
  838. #endif // BOOST_THREAD_USES_CHRONO
  839. #endif // BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
  840. void swap(upgrade_lock& other)BOOST_NOEXCEPT
  841. {
  842. std::swap(m,other.m);
  843. std::swap(is_locked,other.is_locked);
  844. }
  845. Mutex* mutex() const BOOST_NOEXCEPT
  846. {
  847. return m;
  848. }
  849. Mutex* release()BOOST_NOEXCEPT
  850. {
  851. Mutex* const res=m;
  852. m=0;
  853. is_locked=false;
  854. return res;
  855. }
  856. ~upgrade_lock()
  857. {
  858. if (owns_lock())
  859. {
  860. m->unlock_upgrade();
  861. }
  862. }
  863. void lock()
  864. {
  865. if (m == 0)
  866. {
  867. boost::throw_exception(
  868. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost upgrade_lock has no mutex"));
  869. }
  870. if (owns_lock())
  871. {
  872. boost::throw_exception(
  873. boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost upgrade_lock owns already the mutex"));
  874. }
  875. m->lock_upgrade();
  876. is_locked = true;
  877. }
  878. bool try_lock()
  879. {
  880. if (m == 0)
  881. {
  882. boost::throw_exception(
  883. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost upgrade_lock has no mutex"));
  884. }
  885. if (owns_lock())
  886. {
  887. boost::throw_exception(
  888. boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost upgrade_lock owns already the mutex"));
  889. }
  890. is_locked = m->try_lock_upgrade();
  891. return is_locked;
  892. }
  893. void unlock()
  894. {
  895. if (m == 0)
  896. {
  897. boost::throw_exception(
  898. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost upgrade_lock has no mutex"));
  899. }
  900. if (!owns_lock())
  901. {
  902. boost::throw_exception(
  903. boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost upgrade_lock doesn't own the mutex"));
  904. }
  905. m->unlock_upgrade();
  906. is_locked = false;
  907. }
  908. #ifdef BOOST_THREAD_USES_CHRONO
  909. template <class Rep, class Period>
  910. bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
  911. {
  912. if(m==0)
  913. {
  914. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost upgrade_lock has no mutex"));
  915. }
  916. if(owns_lock())
  917. {
  918. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost upgrade_lock owns already the mutex"));
  919. }
  920. is_locked=m->try_lock_upgrade_for(rel_time);
  921. return is_locked;
  922. }
  923. template <class Clock, class Duration>
  924. bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
  925. {
  926. if(m==0)
  927. {
  928. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::operation_not_permitted), "boost upgrade_lock has no mutex"));
  929. }
  930. if(owns_lock())
  931. {
  932. boost::throw_exception(boost::lock_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost upgrade_lock owns already the mutex"));
  933. }
  934. is_locked=m->try_lock_upgrade_until(abs_time);
  935. return is_locked;
  936. }
  937. #endif
  938. #if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  939. typedef void (upgrade_lock::*bool_type)();
  940. operator bool_type() const BOOST_NOEXCEPT
  941. {
  942. return is_locked?&upgrade_lock::lock:0;
  943. }
  944. bool operator!() const BOOST_NOEXCEPT
  945. {
  946. return !owns_lock();
  947. }
  948. #else
  949. explicit operator bool() const BOOST_NOEXCEPT
  950. {
  951. return owns_lock();
  952. }
  953. #endif
  954. bool owns_lock() const BOOST_NOEXCEPT
  955. {
  956. return is_locked;
  957. }
  958. friend class shared_lock<Mutex> ;
  959. friend class unique_lock<Mutex> ;
  960. };
  961. template<typename Mutex>
  962. void swap(upgrade_lock<Mutex>& lhs, upgrade_lock<Mutex>& rhs)
  963. BOOST_NOEXCEPT
  964. {
  965. lhs.swap(rhs);
  966. }
  967. BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) upgrade_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END
  968. template<typename Mutex>
  969. unique_lock<Mutex>::unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other):
  970. m(BOOST_THREAD_RV(other).m),is_locked(BOOST_THREAD_RV(other).is_locked)
  971. {
  972. if(is_locked)
  973. {
  974. m->unlock_upgrade_and_lock();
  975. }
  976. BOOST_THREAD_RV(other).release();
  977. }
  978. template <class Mutex>
  979. class upgrade_to_unique_lock
  980. {
  981. private:
  982. upgrade_lock<Mutex>* source;
  983. unique_lock<Mutex> exclusive;
  984. public:
  985. typedef Mutex mutex_type;
  986. BOOST_THREAD_MOVABLE_ONLY( upgrade_to_unique_lock)
  987. explicit upgrade_to_unique_lock(upgrade_lock<Mutex>& m_) :
  988. source(&m_), exclusive(::boost::move(*source))
  989. {
  990. }
  991. ~upgrade_to_unique_lock()
  992. {
  993. if (source)
  994. {
  995. *source = BOOST_THREAD_MAKE_RV_REF(upgrade_lock<Mutex> (::boost::move(exclusive)));
  996. }
  997. }
  998. upgrade_to_unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_to_unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT:
  999. source(BOOST_THREAD_RV(other).source),exclusive(::boost::move(BOOST_THREAD_RV(other).exclusive))
  1000. {
  1001. BOOST_THREAD_RV(other).source=0;
  1002. }
  1003. //std-2104 unique_lock move-assignment should not be noexcept
  1004. upgrade_to_unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_to_unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
  1005. {
  1006. upgrade_to_unique_lock temp(::boost::move(other));
  1007. swap(temp);
  1008. return *this;
  1009. }
  1010. void swap(upgrade_to_unique_lock& other)BOOST_NOEXCEPT
  1011. {
  1012. std::swap(source,other.source);
  1013. exclusive.swap(other.exclusive);
  1014. }
  1015. #if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  1016. typedef void (upgrade_to_unique_lock::*bool_type)(upgrade_to_unique_lock&);
  1017. operator bool_type() const BOOST_NOEXCEPT
  1018. {
  1019. return exclusive.owns_lock()?&upgrade_to_unique_lock::swap:0;
  1020. }
  1021. bool operator!() const BOOST_NOEXCEPT
  1022. {
  1023. return !owns_lock();
  1024. }
  1025. #else
  1026. explicit operator bool() const BOOST_NOEXCEPT
  1027. {
  1028. return owns_lock();
  1029. }
  1030. #endif
  1031. bool owns_lock() const BOOST_NOEXCEPT
  1032. {
  1033. return exclusive.owns_lock();
  1034. }
  1035. Mutex* mutex() const BOOST_NOEXCEPT
  1036. {
  1037. return exclusive.mutex();
  1038. }
  1039. };
  1040. BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) upgrade_to_unique_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END
  1041. namespace detail
  1042. {
  1043. template<typename Mutex>
  1044. class try_lock_wrapper:
  1045. private unique_lock<Mutex>
  1046. {
  1047. typedef unique_lock<Mutex> base;
  1048. public:
  1049. BOOST_THREAD_MOVABLE_ONLY(try_lock_wrapper)
  1050. try_lock_wrapper()
  1051. {}
  1052. explicit try_lock_wrapper(Mutex& m):
  1053. base(m,try_to_lock)
  1054. {}
  1055. try_lock_wrapper(Mutex& m_,adopt_lock_t):
  1056. base(m_,adopt_lock)
  1057. {
  1058. #if ! defined BOOST_THREAD_PROVIDES_NESTED_LOCKS
  1059. BOOST_ASSERT(is_locked_by_this_thread(m_));
  1060. #endif
  1061. }
  1062. try_lock_wrapper(Mutex& m_,defer_lock_t):
  1063. base(m_,defer_lock)
  1064. {}
  1065. try_lock_wrapper(Mutex& m_,try_to_lock_t):
  1066. base(m_,try_to_lock)
  1067. {}
  1068. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1069. try_lock_wrapper(BOOST_THREAD_RV_REF(try_lock_wrapper) other):
  1070. base(::boost::move(other))
  1071. {}
  1072. #elif defined BOOST_THREAD_USES_MOVE
  1073. try_lock_wrapper(BOOST_THREAD_RV_REF(try_lock_wrapper) other):
  1074. base(::boost::move(static_cast<base&>(other)))
  1075. {}
  1076. #else
  1077. try_lock_wrapper(BOOST_THREAD_RV_REF(try_lock_wrapper) other):
  1078. base(BOOST_THREAD_RV_REF(base)(*other))
  1079. {}
  1080. #endif
  1081. try_lock_wrapper& operator=(BOOST_THREAD_RV_REF_BEG try_lock_wrapper<Mutex> BOOST_THREAD_RV_REF_END other)
  1082. {
  1083. try_lock_wrapper temp(::boost::move(other));
  1084. swap(temp);
  1085. return *this;
  1086. }
  1087. void swap(try_lock_wrapper& other)
  1088. {
  1089. base::swap(other);
  1090. }
  1091. void lock()
  1092. {
  1093. base::lock();
  1094. }
  1095. bool try_lock()
  1096. {
  1097. return base::try_lock();
  1098. }
  1099. void unlock()
  1100. {
  1101. base::unlock();
  1102. }
  1103. bool owns_lock() const
  1104. {
  1105. return base::owns_lock();
  1106. }
  1107. Mutex* mutex() const BOOST_NOEXCEPT
  1108. {
  1109. return base::mutex();
  1110. }
  1111. Mutex* release()
  1112. {
  1113. return base::release();
  1114. }
  1115. #if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
  1116. typedef typename base::bool_type bool_type;
  1117. operator bool_type() const
  1118. {
  1119. return base::operator bool_type();
  1120. }
  1121. bool operator!() const
  1122. {
  1123. return !this->owns_lock();
  1124. }
  1125. #else
  1126. explicit operator bool() const
  1127. {
  1128. return owns_lock();
  1129. }
  1130. #endif
  1131. };
  1132. template<typename Mutex>
  1133. void swap(try_lock_wrapper<Mutex>& lhs,try_lock_wrapper<Mutex>& rhs)
  1134. {
  1135. lhs.swap(rhs);
  1136. }
  1137. }
  1138. }
  1139. #include <boost/config/abi_suffix.hpp>
  1140. #endif