2 * Copyright Andrey Semashev 2007 - 2015.
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)
8 * \file light_rw_mutex.hpp
9 * \author Andrey Semashev
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.
16 #ifndef BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_
17 #define BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_
19 #include <boost/log/detail/config.hpp>
21 #ifdef BOOST_HAS_PRAGMA_ONCE
25 #ifndef BOOST_LOG_NO_THREADS
27 #include <boost/log/detail/header.hpp>
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) && (BOOST_USE_WINAPI_VERSION+0) >= (BOOST_WINAPI_VERSION_WIN6+0)
32 #define BOOST_LOG_LWRWMUTEX_USE_SRWLOCK
33 #elif defined(BOOST_HAS_PTHREADS)
34 #define BOOST_LOG_LWRWMUTEX_USE_PTHREAD
37 #if defined(BOOST_LOG_LWRWMUTEX_USE_SRWLOCK)
39 #include <boost/winapi/srw_lock.hpp>
43 BOOST_LOG_OPEN_NAMESPACE
47 //! A light read/write mutex that uses WinNT 6 and later APIs
50 boost::winapi::SRWLOCK_ m_Mutex;
55 boost::winapi::InitializeSRWLock(&m_Mutex);
59 boost::winapi::AcquireSRWLockShared(&m_Mutex);
63 boost::winapi::ReleaseSRWLockShared(&m_Mutex);
67 boost::winapi::AcquireSRWLockExclusive(&m_Mutex);
71 boost::winapi::ReleaseSRWLockExclusive(&m_Mutex);
75 BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&))
76 BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&))
81 BOOST_LOG_CLOSE_NAMESPACE // namespace log
85 #elif defined(BOOST_LOG_LWRWMUTEX_USE_PTHREAD)
91 BOOST_LOG_OPEN_NAMESPACE
95 //! A light read/write mutex that maps directly onto POSIX threading library
98 pthread_rwlock_t m_Mutex;
103 pthread_rwlock_init(&m_Mutex, NULL);
107 pthread_rwlock_destroy(&m_Mutex);
111 pthread_rwlock_rdlock(&m_Mutex);
115 pthread_rwlock_unlock(&m_Mutex);
119 pthread_rwlock_wrlock(&m_Mutex);
123 pthread_rwlock_unlock(&m_Mutex);
127 BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&))
128 BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&))
133 BOOST_LOG_CLOSE_NAMESPACE // namespace log
141 BOOST_LOG_OPEN_NAMESPACE
145 //! A light read/write mutex
148 struct BOOST_LOG_MAY_ALIAS mutex_state { void* p; } m_Mutex;
151 BOOST_LOG_API light_rw_mutex();
152 BOOST_LOG_API ~light_rw_mutex();
153 BOOST_LOG_API void lock_shared();
154 BOOST_LOG_API void unlock_shared();
155 BOOST_LOG_API void lock();
156 BOOST_LOG_API void unlock();
159 BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&))
160 BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&))
165 BOOST_LOG_CLOSE_NAMESPACE // namespace log
171 #include <boost/log/detail/footer.hpp>
173 #endif // BOOST_LOG_NO_THREADS
175 #endif // BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_