Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.7KB

  1. //
  2. // detail/win_mutex.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_WIN_MUTEX_HPP
  11. #define ASIO_DETAIL_WIN_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. #if defined(ASIO_WINDOWS)
  17. #include "asio/detail/noncopyable.hpp"
  18. #include "asio/detail/scoped_lock.hpp"
  19. #include "asio/detail/socket_types.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. class win_mutex
  24. : private noncopyable
  25. {
  26. public:
  27. typedef asio::detail::scoped_lock<win_mutex> scoped_lock;
  28. // Constructor.
  29. ASIO_DECL win_mutex();
  30. // Destructor.
  31. ~win_mutex()
  32. {
  33. ::DeleteCriticalSection(&crit_section_);
  34. }
  35. // Lock the mutex.
  36. void lock()
  37. {
  38. ::EnterCriticalSection(&crit_section_);
  39. }
  40. // Unlock the mutex.
  41. void unlock()
  42. {
  43. ::LeaveCriticalSection(&crit_section_);
  44. }
  45. private:
  46. // Initialisation must be performed in a separate function to the constructor
  47. // since the compiler does not support the use of structured exceptions and
  48. // C++ exceptions in the same function.
  49. ASIO_DECL int do_init();
  50. ::CRITICAL_SECTION crit_section_;
  51. };
  52. } // namespace detail
  53. } // namespace asio
  54. #include "asio/detail/pop_options.hpp"
  55. #if defined(ASIO_HEADER_ONLY)
  56. # include "asio/detail/impl/win_mutex.ipp"
  57. #endif // defined(ASIO_HEADER_ONLY)
  58. #endif // defined(ASIO_WINDOWS)
  59. #endif // ASIO_DETAIL_WIN_MUTEX_HPP