Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-06 10:03:16

0001 #ifndef BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED
0002 #define BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED
0003 
0004 // Copyright 2023 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #include <boost/config.hpp>
0009 
0010 #if defined(BOOST_SYSTEM_DISABLE_THREADS)
0011 
0012 namespace boost
0013 {
0014 namespace system
0015 {
0016 namespace detail
0017 {
0018 
0019 struct mutex
0020 {
0021     void lock()
0022     {
0023     }
0024 
0025     void unlock()
0026     {
0027     }
0028 };
0029 
0030 } // namespace detail
0031 } // namespace system
0032 } // namespace boost
0033 
0034 #else // defined(BOOST_SYSTEM_DISABLE_THREADS)
0035 
0036 #if defined(BOOST_MSSTL_VERSION) && BOOST_MSSTL_VERSION >= 140
0037 
0038 // Under the MS STL, std::mutex::mutex() is not constexpr, as is
0039 // required by the standard, which leads to initialization order
0040 // issues. However, shared_mutex is based on SRWLock and its
0041 // default constructor is constexpr, so we use that instead.
0042 
0043 #include <boost/winapi/config.hpp>
0044 
0045 // SRWLOCK is not available when targeting Windows XP
0046 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
0047 
0048 #include <shared_mutex>
0049 
0050 #if BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
0051 # define BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX
0052 #endif
0053 
0054 #endif // BOOST_MSSTL_VERSION >= 142 || _HAS_SHARED_MUTEX
0055 
0056 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
0057 
0058 #if defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
0059 
0060 namespace boost
0061 {
0062 namespace system
0063 {
0064 namespace detail
0065 {
0066 
0067 typedef std::shared_mutex mutex;
0068 
0069 } // namespace detail
0070 } // namespace system
0071 } // namespace boost
0072 
0073 #else // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
0074 
0075 #include <mutex>
0076 
0077 namespace boost
0078 {
0079 namespace system
0080 {
0081 namespace detail
0082 {
0083 
0084 using std::mutex;
0085 
0086 } // namespace detail
0087 } // namespace system
0088 } // namespace boost
0089 
0090 #endif // defined(BOOST_SYSTEM_HAS_MSSTL_SHARED_MUTEX)
0091 #endif // defined(BOOST_SYSTEM_DISABLE_THREADS)
0092 
0093 namespace boost
0094 {
0095 namespace system
0096 {
0097 namespace detail
0098 {
0099 
0100 template<class Mtx> class lock_guard
0101 {
0102 private:
0103 
0104     Mtx& mtx_;
0105 
0106 private:
0107 
0108     lock_guard( lock_guard const& );
0109     lock_guard& operator=( lock_guard const& );
0110 
0111 public:
0112 
0113     explicit lock_guard( Mtx& mtx ): mtx_( mtx )
0114     {
0115         mtx_.lock();
0116     }
0117 
0118     ~lock_guard()
0119     {
0120         mtx_.unlock();
0121     }
0122 };
0123 
0124 } // namespace detail
0125 } // namespace system
0126 } // namespace boost
0127 
0128 #endif // #ifndef BOOST_SYSTEM_DETAIL_MUTEX_HPP_INCLUDED