Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:40

0001 //
0002 //  boost/signals2/detail/lwm_pthreads.hpp
0003 //
0004 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
0005 //  Copyright (c) 2008 Frank Mori Hess
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 
0012 #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP
0013 #define BOOST_SIGNALS2_LWM_PTHREADS_HPP
0014 
0015 // MS compatible compilers support #pragma once
0016 
0017 #if defined(_MSC_VER)
0018 # pragma once
0019 #endif
0020 
0021 #include <boost/assert.hpp>
0022 #include <pthread.h>
0023 
0024 namespace boost
0025 {
0026 
0027 namespace signals2
0028 {
0029 
0030 class mutex
0031 {
0032 private:
0033 
0034     pthread_mutex_t m_;
0035 
0036     mutex(mutex const &);
0037     mutex & operator=(mutex const &);
0038 
0039 public:
0040 
0041     mutex()
0042     {
0043 
0044 // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
0045 
0046 #if defined(__hpux) && defined(_DECTHREADS_)
0047         BOOST_VERIFY(pthread_mutex_init(&m_, pthread_mutexattr_default) == 0);
0048 #else
0049         BOOST_VERIFY(pthread_mutex_init(&m_, 0) == 0);
0050 #endif
0051     }
0052 
0053     ~mutex()
0054     {
0055         BOOST_VERIFY(pthread_mutex_destroy(&m_) == 0);
0056     }
0057 
0058     void lock()
0059     {
0060         BOOST_VERIFY(pthread_mutex_lock(&m_) == 0);
0061     }
0062 
0063     bool try_lock()
0064     {
0065         return pthread_mutex_trylock(&m_) == 0;
0066     }
0067 
0068     void unlock()
0069     {
0070         BOOST_VERIFY(pthread_mutex_unlock(&m_) == 0);
0071     }
0072 };
0073 
0074 } // namespace signals2
0075 
0076 } // namespace boost
0077 
0078 #endif // #ifndef BOOST_SIGNALS2_LWM_PTHREADS_HPP