File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_LWM_PTHREADS_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_LWM_PTHREADS_HPP_INCLUDED
0003
0004
0005
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <boost/assert.hpp>
0021 #include <pthread.h>
0022
0023 namespace boost
0024 {
0025
0026 namespace detail
0027 {
0028
0029 class lightweight_mutex
0030 {
0031 private:
0032
0033 pthread_mutex_t m_;
0034
0035 lightweight_mutex(lightweight_mutex const &);
0036 lightweight_mutex & operator=(lightweight_mutex const &);
0037
0038 public:
0039
0040 lightweight_mutex()
0041 {
0042
0043
0044
0045 #if defined(__hpux) && defined(_DECTHREADS_)
0046 BOOST_VERIFY( pthread_mutex_init( &m_, pthread_mutexattr_default ) == 0 );
0047 #else
0048 BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
0049 #endif
0050 }
0051
0052 ~lightweight_mutex()
0053 {
0054 BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
0055 }
0056
0057 class scoped_lock;
0058 friend class scoped_lock;
0059
0060 class scoped_lock
0061 {
0062 private:
0063
0064 pthread_mutex_t & m_;
0065
0066 scoped_lock(scoped_lock const &);
0067 scoped_lock & operator=(scoped_lock const &);
0068
0069 public:
0070
0071 scoped_lock(lightweight_mutex & m): m_(m.m_)
0072 {
0073 BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
0074 }
0075
0076 ~scoped_lock()
0077 {
0078 BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
0079 }
0080 };
0081 };
0082
0083 }
0084
0085 }
0086
0087 #endif