event.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2013.
  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. /*!
  8. * \file detail/event.hpp
  9. * \author Andrey Semashev
  10. * \date 24.07.2011
  11. */
  12. #ifndef BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_
  13. #define BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_
  14. #include <boost/log/detail/config.hpp>
  15. #ifdef BOOST_HAS_PRAGMA_ONCE
  16. #pragma once
  17. #endif
  18. #ifndef BOOST_LOG_NO_THREADS
  19. #if defined(BOOST_THREAD_PLATFORM_PTHREAD)
  20. # if defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0
  21. # if defined(__GNUC__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
  22. # include <semaphore.h>
  23. # include <boost/cstdint.hpp>
  24. # define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE
  25. # endif
  26. # endif
  27. #elif defined(BOOST_THREAD_PLATFORM_WIN32)
  28. # include <boost/cstdint.hpp>
  29. # define BOOST_LOG_EVENT_USE_WINAPI
  30. #endif
  31. #if !defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) && !defined(BOOST_LOG_EVENT_USE_WINAPI)
  32. # include <boost/thread/mutex.hpp>
  33. # include <boost/thread/condition_variable.hpp>
  34. # define BOOST_LOG_EVENT_USE_BOOST_CONDITION
  35. #endif
  36. #include <boost/log/detail/header.hpp>
  37. namespace boost {
  38. BOOST_LOG_OPEN_NAMESPACE
  39. namespace aux {
  40. #if defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE)
  41. class sem_based_event
  42. {
  43. private:
  44. boost::uint32_t m_state;
  45. sem_t m_semaphore;
  46. public:
  47. //! Default constructor
  48. BOOST_LOG_API sem_based_event();
  49. //! Destructor
  50. BOOST_LOG_API ~sem_based_event();
  51. //! Waits for the object to become signalled
  52. BOOST_LOG_API void wait();
  53. //! Sets the object to a signalled state
  54. BOOST_LOG_API void set_signalled();
  55. // Copying prohibited
  56. BOOST_DELETED_FUNCTION(sem_based_event(sem_based_event const&))
  57. BOOST_DELETED_FUNCTION(sem_based_event& operator= (sem_based_event const&))
  58. };
  59. typedef sem_based_event event;
  60. #elif defined(BOOST_LOG_EVENT_USE_WINAPI)
  61. class winapi_based_event
  62. {
  63. private:
  64. boost::uint32_t m_state;
  65. void* m_event;
  66. public:
  67. //! Default constructor
  68. BOOST_LOG_API winapi_based_event();
  69. //! Destructor
  70. BOOST_LOG_API ~winapi_based_event();
  71. //! Waits for the object to become signalled
  72. BOOST_LOG_API void wait();
  73. //! Sets the object to a signalled state
  74. BOOST_LOG_API void set_signalled();
  75. // Copying prohibited
  76. BOOST_DELETED_FUNCTION(winapi_based_event(winapi_based_event const&))
  77. BOOST_DELETED_FUNCTION(winapi_based_event& operator= (winapi_based_event const&))
  78. };
  79. typedef winapi_based_event event;
  80. #else
  81. class generic_event
  82. {
  83. private:
  84. boost::mutex m_mutex;
  85. boost::condition_variable m_cond;
  86. bool m_state;
  87. public:
  88. //! Default constructor
  89. BOOST_LOG_API generic_event();
  90. //! Destructor
  91. BOOST_LOG_API ~generic_event();
  92. //! Waits for the object to become signalled
  93. BOOST_LOG_API void wait();
  94. //! Sets the object to a signalled state
  95. BOOST_LOG_API void set_signalled();
  96. // Copying prohibited
  97. BOOST_DELETED_FUNCTION(generic_event(generic_event const&))
  98. BOOST_DELETED_FUNCTION(generic_event& operator= (generic_event const&))
  99. };
  100. typedef generic_event event;
  101. #endif
  102. } // namespace aux
  103. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  104. } // namespace boost
  105. #include <boost/log/detail/footer.hpp>
  106. #endif // BOOST_LOG_NO_THREADS
  107. #endif // BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_