Line data Source code
1 : // 2 : // boost/signals2/detail/lwm_pthreads.hpp 3 : // 4 : // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. 5 : // Copyright (c) 2008 Frank Mori Hess 6 : // 7 : // Distributed under the Boost Software License, Version 1.0. (See 8 : // accompanying file LICENSE_1_0.txt or copy at 9 : // http://www.boost.org/LICENSE_1_0.txt) 10 : // 11 : 12 : #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP 13 : #define BOOST_SIGNALS2_LWM_PTHREADS_HPP 14 : 15 : // MS compatible compilers support #pragma once 16 : 17 : #if defined(_MSC_VER) 18 : # pragma once 19 : #endif 20 : 21 : #include <boost/assert.hpp> 22 : #include <pthread.h> 23 : 24 : namespace boost 25 : { 26 : 27 : namespace signals2 28 : { 29 : 30 : class mutex 31 : { 32 : private: 33 : 34 : pthread_mutex_t m_; 35 : 36 : mutex(mutex const &); 37 : mutex & operator=(mutex const &); 38 : 39 : public: 40 : 41 179534 : mutex() 42 89767 : { 43 : 44 : // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init 45 : 46 : #if defined(__hpux) && defined(_DECTHREADS_) 47 : BOOST_VERIFY(pthread_mutex_init(&m_, pthread_mutexattr_default) == 0); 48 : #else 49 89767 : BOOST_VERIFY(pthread_mutex_init(&m_, 0) == 0); 50 : #endif 51 179534 : } 52 : 53 60446 : ~mutex() 54 30223 : { 55 30223 : BOOST_VERIFY(pthread_mutex_destroy(&m_) == 0); 56 60446 : } 57 : 58 1779201 : void lock() 59 : { 60 1779201 : BOOST_VERIFY(pthread_mutex_lock(&m_) == 0); 61 1779201 : } 62 : 63 : bool try_lock() 64 : { 65 : return pthread_mutex_trylock(&m_) == 0; 66 : } 67 : 68 1779201 : void unlock() 69 : { 70 1779201 : BOOST_VERIFY(pthread_mutex_unlock(&m_) == 0); 71 1779201 : } 72 : }; 73 : 74 : } // namespace signals2 75 : 76 : } // namespace boost 77 : 78 : #endif // #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP