shared_mutex_ref.qbk 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. [/
  2. (C) Copyright 2007-8 Anthony Williams.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:shared_mutex Class `shared_mutex` -- C++14]
  8. #include <boost/thread/shared_mutex.hpp>
  9. class shared_mutex
  10. {
  11. public:
  12. shared_mutex(shared_mutex const&) = delete;
  13. shared_mutex& operator=(shared_mutex const&) = delete;
  14. shared_mutex();
  15. ~shared_mutex();
  16. void lock_shared();
  17. bool try_lock_shared();
  18. template <class Rep, class Period>
  19. bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
  20. template <class Clock, class Duration>
  21. bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
  22. void unlock_shared();
  23. void lock();
  24. bool try_lock();
  25. template <class Rep, class Period>
  26. bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
  27. template <class Clock, class Duration>
  28. bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  29. void unlock();
  30. #if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
  31. // use upgrade_mutex instead.
  32. void lock_upgrade(); // EXTENSION
  33. void unlock_upgrade(); // EXTENSION
  34. void unlock_upgrade_and_lock(); // EXTENSION
  35. void unlock_and_lock_upgrade(); // EXTENSION
  36. void unlock_and_lock_shared(); // EXTENSION
  37. void unlock_upgrade_and_lock_shared(); // EXTENSION
  38. #endif
  39. #if defined BOOST_THREAD_USES_DATETIME
  40. bool timed_lock_shared(system_time const& timeout); // DEPRECATED
  41. bool timed_lock(system_time const& timeout); // DEPRECATED
  42. #endif
  43. };
  44. The class `boost::shared_mutex` provides an implementation of a multiple-reader / single-writer mutex. It implements the
  45. __shared_lockable_concept__.
  46. Multiple concurrent calls to __lock_ref__, __try_lock_ref__, `__try_lock_for()`, `__try_lock_until()`, __timed_lock_ref__, __lock_shared_ref__,
  47. `__try_lock_shared_for()`, `__try_lock_shared_until()`, __try_lock_shared_ref__ and __timed_lock_shared_ref__ are permitted.
  48. Note the the lack of reader-writer priority policies in shared_mutex. This is due to an algorithm credited to Alexander Terekhov which lets the OS decide which thread is the next to get the lock without caring whether a unique lock or shared lock is being sought. This results in a complete lack of reader or writer starvation. It is simply fair.
  49. [endsect]
  50. [section:upgrade_mutex Class `upgrade_mutex` -- EXTENSION]
  51. #include <boost/thread/shared_mutex.hpp>
  52. class upgrade_mutex
  53. {
  54. public:
  55. upgrade_mutex(upgrade_mutex const&) = delete;
  56. upgrade_mutex& operator=(upgrade_mutex const&) = delete;
  57. upgrade_mutex();
  58. ~upgrade_mutex();
  59. void lock_shared();
  60. bool try_lock_shared();
  61. template <class Rep, class Period>
  62. bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
  63. template <class Clock, class Duration>
  64. bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
  65. void unlock_shared();
  66. void lock();
  67. bool try_lock();
  68. template <class Rep, class Period>
  69. bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
  70. template <class Clock, class Duration>
  71. bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  72. void unlock();
  73. void lock_upgrade();
  74. template <class Rep, class Period>
  75. bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
  76. template <class Clock, class Duration>
  77. bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
  78. void unlock_upgrade();
  79. // Shared <-> Exclusive
  80. #ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
  81. bool try_unlock_shared_and_lock();
  82. template <class Rep, class Period>
  83. bool try_unlock_shared_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
  84. template <class Clock, class Duration>
  85. bool try_unlock_shared_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  86. #endif
  87. void unlock_and_lock_shared();
  88. // Shared <-> Upgrade
  89. #ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
  90. bool try_unlock_shared_and_lock_upgrade();
  91. template <class Rep, class Period>
  92. bool try_unlock_shared_and_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
  93. template <class Clock, class Duration>
  94. bool try_unlock_shared_and_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
  95. #endif
  96. void unlock_upgrade_and_lock_shared();
  97. // Upgrade <-> Exclusive
  98. void unlock_upgrade_and_lock();
  99. #if defined(BOOST_THREAD_PLATFORM_PTHREAD)
  100. || defined(BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN)
  101. bool try_unlock_upgrade_and_lock();
  102. template <class Rep, class Period>
  103. bool try_unlock_upgrade_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
  104. template <class Clock, class Duration>
  105. bool try_unlock_upgrade_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  106. #endif
  107. void unlock_and_lock_upgrade();
  108. };
  109. The class `boost::upgrade_mutex` provides an implementation of a multiple-reader / single-writer mutex. It implements the
  110. __upgrade_lockable_concept__.
  111. Multiple concurrent calls to __lock_ref__, __try_lock_ref__, `__try_lock_for()`, `__try_lock_until()`, __timed_lock_ref__, __lock_shared_ref__,
  112. `__try_lock_shared_for()`, `__try_lock_shared_until()`, __try_lock_shared_ref__ and __timed_lock_shared_ref__ are permitted.
  113. [endsect]
  114. [section:null_mutex Class `null_mutex` -- EXTENSION]
  115. #include <boost/thread/null_mutex.hpp>
  116. class null_mutex
  117. {
  118. public:
  119. null_mutex(null_mutex const&) = delete;
  120. null_mutex& operator=(null_mutex const&) = delete;
  121. null_mutex();
  122. ~null_mutex();
  123. void lock_shared();
  124. bool try_lock_shared();
  125. #ifdef BOOST_THREAD_USES_CHRONO
  126. template <class Rep, class Period>
  127. bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
  128. template <class Clock, class Duration>
  129. bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
  130. #endif
  131. void unlock_shared();
  132. void lock();
  133. bool try_lock();
  134. #ifdef BOOST_THREAD_USES_CHRONO
  135. template <class Rep, class Period>
  136. bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
  137. template <class Clock, class Duration>
  138. bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  139. #endif
  140. void unlock();
  141. void lock_upgrade();
  142. #ifdef BOOST_THREAD_USES_CHRONO
  143. template <class Rep, class Period>
  144. bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
  145. template <class Clock, class Duration>
  146. bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
  147. #endif
  148. void unlock_upgrade();
  149. // Shared <-> Exclusive
  150. bool try_unlock_shared_and_lock();
  151. #ifdef BOOST_THREAD_USES_CHRONO
  152. template <class Rep, class Period>
  153. bool try_unlock_shared_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
  154. template <class Clock, class Duration>
  155. bool try_unlock_shared_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  156. #endif
  157. void unlock_and_lock_shared();
  158. // Shared <-> Upgrade
  159. bool try_unlock_shared_and_lock_upgrade();
  160. #ifdef BOOST_THREAD_USES_CHRONO
  161. template <class Rep, class Period>
  162. bool try_unlock_shared_and_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
  163. template <class Clock, class Duration>
  164. bool try_unlock_shared_and_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
  165. #endif
  166. void unlock_upgrade_and_lock_shared();
  167. // Upgrade <-> Exclusive
  168. void unlock_upgrade_and_lock();
  169. bool try_unlock_upgrade_and_lock();
  170. #ifdef BOOST_THREAD_USES_CHRONO
  171. template <class Rep, class Period>
  172. bool try_unlock_upgrade_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
  173. template <class Clock, class Duration>
  174. bool try_unlock_upgrade_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
  175. #endif
  176. void unlock_and_lock_upgrade();
  177. };
  178. The class `boost::null_mutex` provides a no-op implementation of a multiple-reader / single-writer mutex. It is a model of the
  179. __UpgradeLockable concept.
  180. [endsect]