Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/log/detail/light_rw_mutex.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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 light_rw_mutex.hpp | |
9 * \author Andrey Semashev | |
10 * \date 24.03.2009 | |
11 * | |
12 * \brief This header is the Boost.Log library implementation, see the library documentation | |
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. | |
14 */ | |
15 | |
16 #ifndef BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_ | |
17 #define BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_ | |
18 | |
19 #include <boost/log/detail/config.hpp> | |
20 | |
21 #ifdef BOOST_HAS_PRAGMA_ONCE | |
22 #pragma once | |
23 #endif | |
24 | |
25 #ifndef BOOST_LOG_NO_THREADS | |
26 | |
27 #include <boost/log/detail/header.hpp> | |
28 | |
29 #if defined(BOOST_THREAD_POSIX) // This one can be defined by users, so it should go first | |
30 #define BOOST_LOG_LWRWMUTEX_USE_PTHREAD | |
31 #elif defined(BOOST_WINDOWS) && defined(BOOST_LOG_USE_WINNT6_API) | |
32 #define BOOST_LOG_LWRWMUTEX_USE_SRWLOCK | |
33 #elif defined(BOOST_HAS_PTHREADS) | |
34 #define BOOST_LOG_LWRWMUTEX_USE_PTHREAD | |
35 #endif | |
36 | |
37 #if defined(BOOST_LOG_LWRWMUTEX_USE_SRWLOCK) | |
38 | |
39 #if defined(BOOST_USE_WINDOWS_H) | |
40 | |
41 #ifndef _WIN32_WINNT | |
42 #define _WIN32_WINNT 0x0600 // _WIN32_WINNT_LONGHORN | |
43 #endif | |
44 | |
45 #include <windows.h> | |
46 | |
47 #else // defined(BOOST_USE_WINDOWS_H) | |
48 | |
49 namespace boost { | |
50 | |
51 BOOST_LOG_OPEN_NAMESPACE | |
52 | |
53 namespace aux { | |
54 | |
55 extern "C" { | |
56 | |
57 struct SRWLOCK { void* p; }; | |
58 __declspec(dllimport) void __stdcall InitializeSRWLock(SRWLOCK*); | |
59 __declspec(dllimport) void __stdcall ReleaseSRWLockExclusive(SRWLOCK*); | |
60 __declspec(dllimport) void __stdcall ReleaseSRWLockShared(SRWLOCK*); | |
61 __declspec(dllimport) void __stdcall AcquireSRWLockExclusive(SRWLOCK*); | |
62 __declspec(dllimport) void __stdcall AcquireSRWLockShared(SRWLOCK*); | |
63 | |
64 } // extern "C" | |
65 | |
66 } // namespace aux | |
67 | |
68 BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
69 | |
70 } // namespace boost | |
71 | |
72 #endif // BOOST_USE_WINDOWS_H | |
73 | |
74 namespace boost { | |
75 | |
76 BOOST_LOG_OPEN_NAMESPACE | |
77 | |
78 namespace aux { | |
79 | |
80 //! A light read/write mutex that uses WinNT 6 and later APIs | |
81 class light_rw_mutex | |
82 { | |
83 SRWLOCK m_Mutex; | |
84 | |
85 public: | |
86 light_rw_mutex() | |
87 { | |
88 InitializeSRWLock(&m_Mutex); | |
89 } | |
90 void lock_shared() | |
91 { | |
92 AcquireSRWLockShared(&m_Mutex); | |
93 } | |
94 void unlock_shared() | |
95 { | |
96 ReleaseSRWLockShared(&m_Mutex); | |
97 } | |
98 void lock() | |
99 { | |
100 AcquireSRWLockExclusive(&m_Mutex); | |
101 } | |
102 void unlock() | |
103 { | |
104 ReleaseSRWLockExclusive(&m_Mutex); | |
105 } | |
106 | |
107 // Noncopyable | |
108 BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&)) | |
109 BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&)) | |
110 }; | |
111 | |
112 } // namespace aux | |
113 | |
114 BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
115 | |
116 } // namespace boost | |
117 | |
118 #elif defined(BOOST_LOG_LWRWMUTEX_USE_PTHREAD) | |
119 | |
120 #include <pthread.h> | |
121 | |
122 namespace boost { | |
123 | |
124 BOOST_LOG_OPEN_NAMESPACE | |
125 | |
126 namespace aux { | |
127 | |
128 //! A light read/write mutex that maps directly onto POSIX threading library | |
129 class light_rw_mutex | |
130 { | |
131 pthread_rwlock_t m_Mutex; | |
132 | |
133 public: | |
134 light_rw_mutex() | |
135 { | |
136 pthread_rwlock_init(&m_Mutex, NULL); | |
137 } | |
138 ~light_rw_mutex() | |
139 { | |
140 pthread_rwlock_destroy(&m_Mutex); | |
141 } | |
142 void lock_shared() | |
143 { | |
144 pthread_rwlock_rdlock(&m_Mutex); | |
145 } | |
146 void unlock_shared() | |
147 { | |
148 pthread_rwlock_unlock(&m_Mutex); | |
149 } | |
150 void lock() | |
151 { | |
152 pthread_rwlock_wrlock(&m_Mutex); | |
153 } | |
154 void unlock() | |
155 { | |
156 pthread_rwlock_unlock(&m_Mutex); | |
157 } | |
158 | |
159 // Noncopyable | |
160 BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&)) | |
161 BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&)) | |
162 }; | |
163 | |
164 } // namespace aux | |
165 | |
166 BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
167 | |
168 } // namespace boost | |
169 | |
170 #else | |
171 | |
172 namespace boost { | |
173 | |
174 BOOST_LOG_OPEN_NAMESPACE | |
175 | |
176 namespace aux { | |
177 | |
178 //! A light read/write mutex | |
179 class light_rw_mutex | |
180 { | |
181 struct { void* p; } m_Mutex; | |
182 | |
183 public: | |
184 BOOST_LOG_API light_rw_mutex(); | |
185 BOOST_LOG_API ~light_rw_mutex(); | |
186 BOOST_LOG_API void lock_shared(); | |
187 BOOST_LOG_API void unlock_shared(); | |
188 BOOST_LOG_API void lock(); | |
189 BOOST_LOG_API void unlock(); | |
190 | |
191 // Noncopyable | |
192 BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&)) | |
193 BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&)) | |
194 }; | |
195 | |
196 } // namespace aux | |
197 | |
198 BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
199 | |
200 } // namespace boost | |
201 | |
202 #endif | |
203 | |
204 #include <boost/log/detail/footer.hpp> | |
205 | |
206 #endif // BOOST_LOG_NO_THREADS | |
207 | |
208 #endif // BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_ |