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.

conditionally_enabled_event.hpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // detail/conditionally_enabled_event.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_CONDITIONALLY_ENABLED_EVENT_HPP
  11. #define ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_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 "asio/detail/conditionally_enabled_mutex.hpp"
  17. #include "asio/detail/event.hpp"
  18. #include "asio/detail/noncopyable.hpp"
  19. #include "asio/detail/null_event.hpp"
  20. #include "asio/detail/scoped_lock.hpp"
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. namespace detail {
  24. // Mutex adapter used to conditionally enable or disable locking.
  25. class conditionally_enabled_event
  26. : private noncopyable
  27. {
  28. public:
  29. // Constructor.
  30. conditionally_enabled_event()
  31. {
  32. }
  33. // Destructor.
  34. ~conditionally_enabled_event()
  35. {
  36. }
  37. // Signal the event. (Retained for backward compatibility.)
  38. void signal(conditionally_enabled_mutex::scoped_lock& lock)
  39. {
  40. if (lock.mutex_.enabled_)
  41. event_.signal(lock);
  42. }
  43. // Signal all waiters.
  44. void signal_all(conditionally_enabled_mutex::scoped_lock& lock)
  45. {
  46. if (lock.mutex_.enabled_)
  47. event_.signal_all(lock);
  48. }
  49. // Unlock the mutex and signal one waiter.
  50. void unlock_and_signal_one(
  51. conditionally_enabled_mutex::scoped_lock& lock)
  52. {
  53. if (lock.mutex_.enabled_)
  54. event_.unlock_and_signal_one(lock);
  55. }
  56. // If there's a waiter, unlock the mutex and signal it.
  57. bool maybe_unlock_and_signal_one(
  58. conditionally_enabled_mutex::scoped_lock& lock)
  59. {
  60. if (lock.mutex_.enabled_)
  61. return event_.maybe_unlock_and_signal_one(lock);
  62. else
  63. return false;
  64. }
  65. // Reset the event.
  66. void clear(conditionally_enabled_mutex::scoped_lock& lock)
  67. {
  68. if (lock.mutex_.enabled_)
  69. event_.clear(lock);
  70. }
  71. // Wait for the event to become signalled.
  72. void wait(conditionally_enabled_mutex::scoped_lock& lock)
  73. {
  74. if (lock.mutex_.enabled_)
  75. event_.wait(lock);
  76. else
  77. null_event().wait(lock);
  78. }
  79. // Timed wait for the event to become signalled.
  80. bool wait_for_usec(
  81. conditionally_enabled_mutex::scoped_lock& lock, long usec)
  82. {
  83. if (lock.mutex_.enabled_)
  84. return event_.wait_for_usec(lock, usec);
  85. else
  86. return null_event().wait_for_usec(lock, usec);
  87. }
  88. private:
  89. asio::detail::event event_;
  90. };
  91. } // namespace detail
  92. } // namespace asio
  93. #include "asio/detail/pop_options.hpp"
  94. #endif // ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_HPP