Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file detail/event.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 24.07.2011
|
Chris@16
|
11 */
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_
|
Chris@16
|
14 #define BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/log/detail/config.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
19 #pragma once
|
Chris@16
|
20 #endif
|
Chris@16
|
21
|
Chris@16
|
22 #ifndef BOOST_LOG_NO_THREADS
|
Chris@16
|
23
|
Chris@16
|
24 #if defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
Chris@16
|
25 # if defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0
|
Chris@16
|
26 # if defined(__GNUC__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
|
Chris@16
|
27 # include <semaphore.h>
|
Chris@16
|
28 # include <boost/cstdint.hpp>
|
Chris@16
|
29 # define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE
|
Chris@16
|
30 # endif
|
Chris@16
|
31 # endif
|
Chris@16
|
32 #elif defined(BOOST_THREAD_PLATFORM_WIN32)
|
Chris@16
|
33 # include <boost/cstdint.hpp>
|
Chris@16
|
34 # define BOOST_LOG_EVENT_USE_WINAPI
|
Chris@16
|
35 #endif
|
Chris@16
|
36
|
Chris@16
|
37 #if !defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) && !defined(BOOST_LOG_EVENT_USE_WINAPI)
|
Chris@16
|
38 # include <boost/thread/mutex.hpp>
|
Chris@16
|
39 # include <boost/thread/condition_variable.hpp>
|
Chris@16
|
40 # define BOOST_LOG_EVENT_USE_BOOST_CONDITION
|
Chris@16
|
41 #endif
|
Chris@16
|
42
|
Chris@16
|
43 #include <boost/log/detail/header.hpp>
|
Chris@16
|
44
|
Chris@16
|
45 namespace boost {
|
Chris@16
|
46
|
Chris@16
|
47 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
48
|
Chris@16
|
49 namespace aux {
|
Chris@16
|
50
|
Chris@16
|
51 #if defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE)
|
Chris@16
|
52
|
Chris@16
|
53 class sem_based_event
|
Chris@16
|
54 {
|
Chris@16
|
55 private:
|
Chris@16
|
56 boost::uint32_t m_state;
|
Chris@16
|
57 sem_t m_semaphore;
|
Chris@16
|
58
|
Chris@16
|
59 public:
|
Chris@16
|
60 //! Default constructor
|
Chris@16
|
61 BOOST_LOG_API sem_based_event();
|
Chris@16
|
62 //! Destructor
|
Chris@16
|
63 BOOST_LOG_API ~sem_based_event();
|
Chris@16
|
64
|
Chris@16
|
65 //! Waits for the object to become signalled
|
Chris@16
|
66 BOOST_LOG_API void wait();
|
Chris@16
|
67 //! Sets the object to a signalled state
|
Chris@16
|
68 BOOST_LOG_API void set_signalled();
|
Chris@16
|
69
|
Chris@16
|
70 // Copying prohibited
|
Chris@16
|
71 BOOST_DELETED_FUNCTION(sem_based_event(sem_based_event const&))
|
Chris@16
|
72 BOOST_DELETED_FUNCTION(sem_based_event& operator= (sem_based_event const&))
|
Chris@16
|
73 };
|
Chris@16
|
74
|
Chris@16
|
75 typedef sem_based_event event;
|
Chris@16
|
76
|
Chris@16
|
77 #elif defined(BOOST_LOG_EVENT_USE_WINAPI)
|
Chris@16
|
78
|
Chris@16
|
79 class winapi_based_event
|
Chris@16
|
80 {
|
Chris@16
|
81 private:
|
Chris@16
|
82 boost::uint32_t m_state;
|
Chris@16
|
83 void* m_event;
|
Chris@16
|
84
|
Chris@16
|
85 public:
|
Chris@16
|
86 //! Default constructor
|
Chris@16
|
87 BOOST_LOG_API winapi_based_event();
|
Chris@16
|
88 //! Destructor
|
Chris@16
|
89 BOOST_LOG_API ~winapi_based_event();
|
Chris@16
|
90
|
Chris@16
|
91 //! Waits for the object to become signalled
|
Chris@16
|
92 BOOST_LOG_API void wait();
|
Chris@16
|
93 //! Sets the object to a signalled state
|
Chris@16
|
94 BOOST_LOG_API void set_signalled();
|
Chris@16
|
95
|
Chris@16
|
96 // Copying prohibited
|
Chris@16
|
97 BOOST_DELETED_FUNCTION(winapi_based_event(winapi_based_event const&))
|
Chris@16
|
98 BOOST_DELETED_FUNCTION(winapi_based_event& operator= (winapi_based_event const&))
|
Chris@16
|
99 };
|
Chris@16
|
100
|
Chris@16
|
101 typedef winapi_based_event event;
|
Chris@16
|
102
|
Chris@16
|
103 #else
|
Chris@16
|
104
|
Chris@16
|
105 class generic_event
|
Chris@16
|
106 {
|
Chris@16
|
107 private:
|
Chris@16
|
108 boost::mutex m_mutex;
|
Chris@16
|
109 boost::condition_variable m_cond;
|
Chris@16
|
110 bool m_state;
|
Chris@16
|
111
|
Chris@16
|
112 public:
|
Chris@16
|
113 //! Default constructor
|
Chris@16
|
114 BOOST_LOG_API generic_event();
|
Chris@16
|
115 //! Destructor
|
Chris@16
|
116 BOOST_LOG_API ~generic_event();
|
Chris@16
|
117
|
Chris@16
|
118 //! Waits for the object to become signalled
|
Chris@16
|
119 BOOST_LOG_API void wait();
|
Chris@16
|
120 //! Sets the object to a signalled state
|
Chris@16
|
121 BOOST_LOG_API void set_signalled();
|
Chris@16
|
122
|
Chris@16
|
123 // Copying prohibited
|
Chris@16
|
124 BOOST_DELETED_FUNCTION(generic_event(generic_event const&))
|
Chris@16
|
125 BOOST_DELETED_FUNCTION(generic_event& operator= (generic_event const&))
|
Chris@16
|
126 };
|
Chris@16
|
127
|
Chris@16
|
128 typedef generic_event event;
|
Chris@16
|
129
|
Chris@16
|
130 #endif
|
Chris@16
|
131
|
Chris@16
|
132 } // namespace aux
|
Chris@16
|
133
|
Chris@16
|
134 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
135
|
Chris@16
|
136 } // namespace boost
|
Chris@16
|
137
|
Chris@16
|
138 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
139
|
Chris@16
|
140 #endif // BOOST_LOG_NO_THREADS
|
Chris@16
|
141
|
Chris@16
|
142 #endif // BOOST_LOG_DETAIL_EVENT_HPP_INCLUDED_
|