lwm_pthreads.hpp
Go to the documentation of this file.
00001 #ifndef BOOST_SMART_PTR_DETAIL_LWM_PTHREADS_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_LWM_PTHREADS_HPP_INCLUDED
00003 
00004 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  boost/detail/lwm_pthreads.hpp
00012 //
00013 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
00014 //
00015 // Distributed under the Boost Software License, Version 1.0. (See
00016 // accompanying file LICENSE_1_0.txt or copy at
00017 // http://www.boost.org/LICENSE_1_0.txt)
00018 //
00019 
00020 #include <pthread.h>
00021 
00022 namespace boost
00023 {
00024 
00025 namespace detail
00026 {
00027 
00028 class lightweight_mutex
00029 {
00030 private:
00031 
00032     pthread_mutex_t m_;
00033 
00034     lightweight_mutex(lightweight_mutex const &);
00035     lightweight_mutex & operator=(lightweight_mutex const &);
00036 
00037 public:
00038 
00039     lightweight_mutex()
00040     {
00041 
00042 // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
00043 
00044 #if defined(__hpux) && defined(_DECTHREADS_)
00045         pthread_mutex_init(&m_, pthread_mutexattr_default);
00046 #else
00047         pthread_mutex_init(&m_, 0);
00048 #endif
00049     }
00050 
00051     ~lightweight_mutex()
00052     {
00053         pthread_mutex_destroy(&m_);
00054     }
00055 
00056     class scoped_lock;
00057     friend class scoped_lock;
00058 
00059     class scoped_lock
00060     {
00061     private:
00062 
00063         pthread_mutex_t & m_;
00064 
00065         scoped_lock(scoped_lock const &);
00066         scoped_lock & operator=(scoped_lock const &);
00067 
00068     public:
00069 
00070         scoped_lock(lightweight_mutex & m): m_(m.m_)
00071         {
00072             pthread_mutex_lock(&m_);
00073         }
00074 
00075         ~scoped_lock()
00076         {
00077             pthread_mutex_unlock(&m_);
00078         }
00079     };
00080 };
00081 
00082 } // namespace detail
00083 
00084 } // namespace boost
00085 
00086 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_PTHREADS_HPP_INCLUDED


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29