null_mutex.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Vicente J. Botet Escriba 2008-2009,2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/thread for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_THREAD_NULL_MUTEX_HPP
  11. #define BOOST_THREAD_NULL_MUTEX_HPP
  12. #include <boost/thread/detail/config.hpp>
  13. #include <boost/thread/detail/delete.hpp>
  14. #include <boost/chrono/chrono.hpp>
  15. /// \file
  16. /// Describes null_mutex class
  17. namespace boost
  18. {
  19. /// Implements a mutex that simulates a mutex without doing any operation and
  20. /// simulates a successful operation.
  21. class null_mutex
  22. {
  23. public:
  24. BOOST_THREAD_NO_COPYABLE( null_mutex) /*< no copyable >*/
  25. null_mutex() {}
  26. /// Simulates a mutex lock() operation. Empty function.
  27. void lock()
  28. {
  29. }
  30. /// Simulates a mutex try_lock() operation.
  31. /// Equivalent to "return true;"
  32. bool try_lock()
  33. {
  34. return true;
  35. }
  36. /// Simulates a mutex unlock() operation.
  37. /// Empty function.
  38. void unlock()
  39. {
  40. }
  41. #ifdef BOOST_THREAD_USES_CHRONO
  42. /// Simulates a mutex try_lock_until() operation.
  43. /// Equivalent to "return true;"
  44. template <typename Clock, typename Duration>
  45. bool try_lock_until(chrono::time_point<Clock, Duration> const &)
  46. {
  47. return true;
  48. }
  49. /// Simulates a mutex try_lock_for() operation.
  50. /// Equivalent to "return true;"
  51. template <typename Rep, typename Period>
  52. bool try_lock_for(chrono::duration<Rep, Period> const &)
  53. {
  54. return true;
  55. }
  56. #endif
  57. /// Simulates a mutex lock_shared() operation.
  58. /// Empty function.
  59. void lock_shared()
  60. {
  61. }
  62. /// Simulates a mutex try_lock_shared() operation.
  63. /// Equivalent to "return true;"
  64. bool try_lock_shared()
  65. {
  66. return true;
  67. }
  68. /// Simulates a mutex unlock_shared() operation.
  69. /// Empty function.
  70. void unlock_shared()
  71. {
  72. }
  73. /// Simulates a mutex try_lock_shared_until() operation.
  74. /// Equivalent to "return true;"
  75. template <typename Clock, typename Duration>
  76. bool try_lock_shared_until(chrono::time_point<Clock, Duration> const &)
  77. {
  78. return true;
  79. }
  80. /// Simulates a mutex try_lock_shared_for() operation.
  81. /// Equivalent to "return true;"
  82. template <typename Rep, typename Period>
  83. bool try_lock_shared_for(chrono::duration<Rep, Period> const &)
  84. {
  85. return true;
  86. }
  87. /// Simulates a mutex lock_upgrade() operation.
  88. /// Empty function.
  89. void lock_upgrade()
  90. {
  91. }
  92. /// Simulates a mutex try_lock_upgrade() operation.
  93. /// Equivalent to "return true;"
  94. bool try_lock_upgrade()
  95. {
  96. return true;
  97. }
  98. /// Simulates a mutex unlock_upgrade() operation.
  99. /// Empty function.
  100. void unlock_upgrade()
  101. {
  102. }
  103. /// Simulates a mutex try_lock_upgrade_until() operation.
  104. /// Equivalent to "return true;"
  105. template <typename Clock, typename Duration>
  106. bool try_lock_upgrade_until(chrono::time_point<Clock, Duration> const &)
  107. {
  108. return true;
  109. }
  110. /// Simulates a mutex try_lock_upgrade_for() operation.
  111. /// Equivalent to "return true;"
  112. template <typename Rep, typename Period>
  113. bool try_lock_upgrade_for(chrono::duration<Rep, Period> const &)
  114. {
  115. return true;
  116. }
  117. /// Simulates a mutex try_unlock_shared_and_lock() operation.
  118. /// Equivalent to "return true;"
  119. bool try_unlock_shared_and_lock()
  120. {
  121. return true;
  122. }
  123. #ifdef BOOST_THREAD_USES_CHRONO
  124. /// Simulates a mutex try_unlock_shared_and_lock_until() operation.
  125. /// Equivalent to "return true;"
  126. template <typename Clock, typename Duration>
  127. bool try_unlock_shared_and_lock_until(chrono::time_point<Clock, Duration> const &)
  128. {
  129. return true;
  130. }
  131. /// Simulates a mutex try_unlock_shared_and_lock_for() operation.
  132. /// Equivalent to "return true;"
  133. template <typename Rep, typename Period>
  134. bool try_unlock_shared_and_lock_for(chrono::duration<Rep, Period> const &)
  135. {
  136. return true;
  137. }
  138. #endif
  139. /// Simulates unlock_and_lock_shared().
  140. /// Empty function.
  141. void unlock_and_lock_shared()
  142. {
  143. }
  144. /// Simulates a mutex try_unlock_shared_and_lock_upgrade() operation.
  145. /// Equivalent to "return true;"
  146. bool try_unlock_shared_and_lock_upgrade()
  147. {
  148. return true;
  149. }
  150. #ifdef BOOST_THREAD_USES_CHRONO
  151. /// Simulates a mutex try_unlock_shared_and_lock_upgrade_until() operation.
  152. /// Equivalent to "return true;"
  153. template <typename Clock, typename Duration>
  154. bool try_unlock_shared_and_lock_upgrade_until(chrono::time_point<Clock, Duration> const &)
  155. {
  156. return true;
  157. }
  158. /// Simulates a mutex try_unlock_shared_and_lock_upgrade_for() operation.
  159. /// Equivalent to "return true;"
  160. template <typename Rep, typename Period>
  161. bool try_unlock_shared_and_lock_upgrade_for(chrono::duration<Rep, Period> const &)
  162. {
  163. return true;
  164. }
  165. #endif
  166. /// Simulates unlock_and_lock_upgrade().
  167. /// Empty function.
  168. void unlock_and_lock_upgrade()
  169. {
  170. }
  171. /// Simulates unlock_upgrade_and_lock().
  172. /// Empty function.
  173. void unlock_upgrade_and_lock()
  174. {
  175. }
  176. /// Simulates a mutex try_unlock_upgrade_and_lock() operation.
  177. /// Equivalent to "return true;"
  178. bool try_unlock_upgrade_and_lock()
  179. {
  180. return true;
  181. }
  182. #ifdef BOOST_THREAD_USES_CHRONO
  183. /// Simulates a mutex try_unlock_upgrade_and_lock_until() operation.
  184. /// Equivalent to "return true;"
  185. template <typename Clock, typename Duration>
  186. bool try_unlock_upgrade_and_lock_until(chrono::time_point<Clock, Duration> const &)
  187. {
  188. return true;
  189. }
  190. /// Simulates a mutex try_unlock_upgrade_and_lock_for() operation.
  191. /// Equivalent to "return true;"
  192. template <typename Rep, typename Period>
  193. bool try_unlock_upgrade_and_lock_for(chrono::duration<Rep, Period> const &)
  194. {
  195. return true;
  196. }
  197. #endif
  198. /// Simulates unlock_upgrade_and_lock_shared().
  199. /// Empty function.
  200. void unlock_upgrade_and_lock_shared()
  201. {
  202. }
  203. };
  204. } //namespace boost {
  205. #endif