std_static_mutex.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // detail/std_static_mutex.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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. #ifndef ASIO_DETAIL_STD_STATIC_MUTEX_HPP
  11. #define ASIO_DETAIL_STD_STATIC_MUTEX_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include <mutex>
  17. #include "asio/detail/noncopyable.hpp"
  18. #include "asio/detail/scoped_lock.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. class std_event;
  23. class std_static_mutex
  24. : private noncopyable
  25. {
  26. public:
  27. typedef asio::detail::scoped_lock<std_static_mutex> scoped_lock;
  28. // Constructor.
  29. std_static_mutex(int)
  30. {
  31. }
  32. // Destructor.
  33. ~std_static_mutex()
  34. {
  35. }
  36. // Initialise the mutex.
  37. void init()
  38. {
  39. // Nothing to do.
  40. }
  41. // Lock the mutex.
  42. void lock()
  43. {
  44. mutex_.lock();
  45. }
  46. // Unlock the mutex.
  47. void unlock()
  48. {
  49. mutex_.unlock();
  50. }
  51. private:
  52. friend class std_event;
  53. std::mutex mutex_;
  54. };
  55. #define ASIO_STD_STATIC_MUTEX_INIT 0
  56. } // namespace detail
  57. } // namespace asio
  58. #include "asio/detail/pop_options.hpp"
  59. #endif // ASIO_DETAIL_STD_STATIC_MUTEX_HPP