Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:21

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   light_rw_mutex.hpp
0009  * \author Andrey Semashev
0010  * \date   24.03.2009
0011  *
0012  * \brief  This header is the Boost.Log library implementation, see the library documentation
0013  *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
0014  */
0015 
0016 #ifndef BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_
0017 #define BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_
0018 
0019 #include <boost/log/detail/config.hpp>
0020 
0021 #ifdef BOOST_HAS_PRAGMA_ONCE
0022 #pragma once
0023 #endif
0024 
0025 #ifndef BOOST_LOG_NO_THREADS
0026 
0027 #include <boost/log/detail/header.hpp>
0028 
0029 #if defined(BOOST_THREAD_POSIX) // This one can be defined by users, so it should go first
0030 #define BOOST_LOG_LWRWMUTEX_USE_PTHREAD
0031 #elif defined(BOOST_WINDOWS) && (BOOST_USE_WINAPI_VERSION+0) >= (BOOST_WINAPI_VERSION_WIN6+0)
0032 #define BOOST_LOG_LWRWMUTEX_USE_SRWLOCK
0033 #elif defined(BOOST_HAS_PTHREADS)
0034 #define BOOST_LOG_LWRWMUTEX_USE_PTHREAD
0035 #endif
0036 
0037 #if defined(BOOST_LOG_LWRWMUTEX_USE_SRWLOCK)
0038 
0039 #include <boost/winapi/srw_lock.hpp>
0040 
0041 namespace boost {
0042 
0043 BOOST_LOG_OPEN_NAMESPACE
0044 
0045 namespace aux {
0046 
0047 //! A light read/write mutex that uses WinNT 6 and later APIs
0048 class light_rw_mutex
0049 {
0050     boost::winapi::SRWLOCK_ m_Mutex;
0051 
0052 public:
0053     light_rw_mutex()
0054     {
0055         boost::winapi::InitializeSRWLock(&m_Mutex);
0056     }
0057     void lock_shared()
0058     {
0059         boost::winapi::AcquireSRWLockShared(&m_Mutex);
0060     }
0061     void unlock_shared()
0062     {
0063         boost::winapi::ReleaseSRWLockShared(&m_Mutex);
0064     }
0065     void lock()
0066     {
0067         boost::winapi::AcquireSRWLockExclusive(&m_Mutex);
0068     }
0069     void unlock()
0070     {
0071         boost::winapi::ReleaseSRWLockExclusive(&m_Mutex);
0072     }
0073 
0074     // Noncopyable
0075     BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&))
0076     BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&))
0077 };
0078 
0079 } // namespace aux
0080 
0081 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0082 
0083 } // namespace boost
0084 
0085 #elif defined(BOOST_LOG_LWRWMUTEX_USE_PTHREAD)
0086 
0087 #include <pthread.h>
0088 
0089 namespace boost {
0090 
0091 BOOST_LOG_OPEN_NAMESPACE
0092 
0093 namespace aux {
0094 
0095 //! A light read/write mutex that maps directly onto POSIX threading library
0096 class light_rw_mutex
0097 {
0098     pthread_rwlock_t m_Mutex;
0099 
0100 public:
0101     light_rw_mutex()
0102     {
0103         pthread_rwlock_init(&m_Mutex, NULL);
0104     }
0105     ~light_rw_mutex()
0106     {
0107         pthread_rwlock_destroy(&m_Mutex);
0108     }
0109     void lock_shared()
0110     {
0111         pthread_rwlock_rdlock(&m_Mutex);
0112     }
0113     void unlock_shared()
0114     {
0115         pthread_rwlock_unlock(&m_Mutex);
0116     }
0117     void lock()
0118     {
0119         pthread_rwlock_wrlock(&m_Mutex);
0120     }
0121     void unlock()
0122     {
0123         pthread_rwlock_unlock(&m_Mutex);
0124     }
0125 
0126     // Noncopyable
0127     BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&))
0128     BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&))
0129 };
0130 
0131 } // namespace aux
0132 
0133 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0134 
0135 } // namespace boost
0136 
0137 #else
0138 
0139 namespace boost {
0140 
0141 BOOST_LOG_OPEN_NAMESPACE
0142 
0143 namespace aux {
0144 
0145 //! A light read/write mutex
0146 class light_rw_mutex
0147 {
0148     struct BOOST_LOG_MAY_ALIAS mutex_state { void* p; } m_Mutex;
0149 
0150 public:
0151     BOOST_LOG_API light_rw_mutex();
0152     BOOST_LOG_API ~light_rw_mutex();
0153     BOOST_LOG_API void lock_shared();
0154     BOOST_LOG_API void unlock_shared();
0155     BOOST_LOG_API void lock();
0156     BOOST_LOG_API void unlock();
0157 
0158     // Noncopyable
0159     BOOST_DELETED_FUNCTION(light_rw_mutex(light_rw_mutex const&))
0160     BOOST_DELETED_FUNCTION(light_rw_mutex& operator= (light_rw_mutex const&))
0161 };
0162 
0163 } // namespace aux
0164 
0165 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0166 
0167 } // namespace boost
0168 
0169 #endif
0170 
0171 #include <boost/log/detail/footer.hpp>
0172 
0173 #endif // BOOST_LOG_NO_THREADS
0174 
0175 #endif // BOOST_LOG_DETAIL_LIGHT_RW_MUTEX_HPP_INCLUDED_