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 6916 : mutex() 42 3458 : { 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 3458 : BOOST_VERIFY(pthread_mutex_init(&m_, 0) == 0); 50 : #endif 51 6916 : } 52 : 53 1660 : ~mutex() 54 830 : { 55 830 : BOOST_VERIFY(pthread_mutex_destroy(&m_) == 0); 56 1660 : } 57 : 58 83918 : void lock() 59 : { 60 83918 : BOOST_VERIFY(pthread_mutex_lock(&m_) == 0); 61 83918 : } 62 : 63 : bool try_lock() 64 : { 65 : return pthread_mutex_trylock(&m_) == 0; 66 : } 67 : 68 83918 : void unlock() 69 : { 70 83918 : BOOST_VERIFY(pthread_mutex_unlock(&m_) == 0); 71 83918 : } 72 : }; 73 : 74 : } // namespace signals2 75 : 76 : } // namespace boost 77 : 78 : #endif // #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP