src/sysc/packages/boost/detail/lwm_pthreads.hpp

Go to the documentation of this file.
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 //  boost/detail/lwm_pthreads.hpp
00010 //
00011 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
00012 //
00013 //  Permission to copy, use, modify, sell and distribute this software
00014 //  is granted provided this copyright notice appears in all copies.
00015 //  This software is provided "as is" without express or implied
00016 //  warranty, and with no claim as to its suitability for any purpose.
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 // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
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 } // namespace detail
00082 
00083 } // namespace boost
00084 
00085 #endif // #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1