00001 #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
00002 #define BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
00003
00004 #if _MSC_VER >= 1020
00005 #pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <pthread.h>
00020
00021 namespace boost
00022 {
00023
00024 namespace detail
00025 {
00026
00027 class lightweight_mutex
00028 {
00029 private:
00030
00031 pthread_mutex_t m_;
00032
00033 lightweight_mutex(lightweight_mutex const &);
00034 lightweight_mutex & operator=(lightweight_mutex const &);
00035
00036 public:
00037
00038 lightweight_mutex()
00039 {
00040
00041
00042
00043 #if defined(__hpux) && defined(_DECTHREADS_)
00044 pthread_mutex_init(&m_, pthread_mutexattr_default);
00045 #else
00046 pthread_mutex_init(&m_, 0);
00047 #endif
00048 }
00049
00050 ~lightweight_mutex()
00051 {
00052 pthread_mutex_destroy(&m_);
00053 }
00054
00055 class scoped_lock;
00056 friend class scoped_lock;
00057
00058 class scoped_lock
00059 {
00060 private:
00061
00062 pthread_mutex_t & m_;
00063
00064 scoped_lock(scoped_lock const &);
00065 scoped_lock & operator=(scoped_lock const &);
00066
00067 public:
00068
00069 scoped_lock(lightweight_mutex & m): m_(m.m_)
00070 {
00071 pthread_mutex_lock(&m_);
00072 }
00073
00074 ~scoped_lock()
00075 {
00076 pthread_mutex_unlock(&m_);
00077 }
00078 };
00079 };
00080
00081 }
00082
00083 }
00084
00085 #endif // #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED