File indexing completed on 2025-12-15 09:46:03
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_FLYWEIGHT_DETAIL_RECURSIVE_LW_MUTEX_HPP
0010 #define BOOST_FLYWEIGHT_DETAIL_RECURSIVE_LW_MUTEX_HPP
0011
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include <boost/config.hpp>
0026
0027 #if !defined(BOOST_NO_CXX11_HDR_MUTEX)
0028 #include <boost/noncopyable.hpp>
0029 #include <mutex>
0030
0031 namespace boost{
0032
0033 namespace flyweights{
0034
0035 namespace detail{
0036
0037 struct recursive_lightweight_mutex:noncopyable
0038 {
0039 recursive_lightweight_mutex(){}
0040
0041 struct scoped_lock;
0042 friend struct scoped_lock;
0043 struct scoped_lock:noncopyable
0044 {
0045 public:
0046 scoped_lock(recursive_lightweight_mutex& m):m_(m.m_){m_.lock();}
0047 ~scoped_lock(){m_.unlock();}
0048
0049 private:
0050 std::recursive_mutex& m_;
0051 };
0052
0053 private:
0054 std::recursive_mutex m_;
0055 };
0056
0057 }
0058
0059 }
0060
0061 }
0062 #elif defined(BOOST_HAS_PTHREADS)
0063
0064
0065 #include <boost/assert.hpp>
0066 #include <boost/noncopyable.hpp>
0067 #include <pthread.h>
0068
0069 namespace boost{
0070
0071 namespace flyweights{
0072
0073 namespace detail{
0074
0075 struct recursive_lightweight_mutex:noncopyable
0076 {
0077 recursive_lightweight_mutex()
0078 {
0079 pthread_mutexattr_t attr;
0080 BOOST_VERIFY(pthread_mutexattr_init(&attr)==0);
0081 BOOST_VERIFY(pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE)==0);
0082 BOOST_VERIFY(pthread_mutex_init(&m_,&attr)==0);
0083 BOOST_VERIFY(pthread_mutexattr_destroy(&attr)==0);
0084 }
0085
0086 ~recursive_lightweight_mutex(){pthread_mutex_destroy(&m_);}
0087
0088 struct scoped_lock;
0089 friend struct scoped_lock;
0090 struct scoped_lock:noncopyable
0091 {
0092 public:
0093 scoped_lock(recursive_lightweight_mutex& m):m_(m.m_)
0094 {
0095 BOOST_VERIFY(pthread_mutex_lock(&m_)==0);
0096 }
0097
0098 ~scoped_lock(){BOOST_VERIFY(pthread_mutex_unlock(&m_)==0);}
0099
0100 private:
0101 pthread_mutex_t& m_;
0102 };
0103
0104 private:
0105 pthread_mutex_t m_;
0106 };
0107
0108 }
0109
0110 }
0111
0112 }
0113 #elif defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
0114 #include <boost/smart_ptr/detail/lightweight_mutex.hpp>
0115
0116 namespace boost{
0117
0118 namespace flyweights{
0119
0120 namespace detail{
0121
0122 typedef boost::detail::lightweight_mutex recursive_lightweight_mutex;
0123
0124 }
0125
0126 }
0127
0128 }
0129 #else
0130 namespace boost{
0131
0132 namespace flyweights{
0133
0134 namespace detail{
0135
0136 struct recursive_lightweight_mutex
0137 {
0138 typedef recursive_lightweight_mutex scoped_lock;
0139 };
0140
0141 }
0142
0143 }
0144
0145 }
0146 #endif
0147
0148 #endif