Ugly, not-to-be-pushed sucking in of all of Boost to get windows to work.
[dyninst.git] / external / boost / detail / lwm_pthreads.hpp
1 #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
2 #define BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 //  boost/detail/lwm_pthreads.hpp
12 //
13 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
14 //
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 //
19
20 #include <pthread.h>
21
22 namespace boost
23 {
24
25 namespace detail
26 {
27
28 class lightweight_mutex
29 {
30 private:
31
32     pthread_mutex_t m_;
33
34     lightweight_mutex(lightweight_mutex const &);
35     lightweight_mutex & operator=(lightweight_mutex const &);
36
37 public:
38
39     lightweight_mutex()
40     {
41
42 // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
43
44 #if defined(__hpux) && defined(_DECTHREADS_)
45         pthread_mutex_init(&m_, pthread_mutexattr_default);
46 #else
47         pthread_mutex_init(&m_, 0);
48 #endif
49     }
50
51     ~lightweight_mutex()
52     {
53         pthread_mutex_destroy(&m_);
54     }
55
56     class scoped_lock;
57     friend class scoped_lock;
58
59     class scoped_lock
60     {
61     private:
62
63         pthread_mutex_t & m_;
64
65         scoped_lock(scoped_lock const &);
66         scoped_lock & operator=(scoped_lock const &);
67
68     public:
69
70         scoped_lock(lightweight_mutex & m): m_(m.m_)
71         {
72             pthread_mutex_lock(&m_);
73         }
74
75         ~scoped_lock()
76         {
77             pthread_mutex_unlock(&m_);
78         }
79     };
80 };
81
82 } // namespace detail
83
84 } // namespace boost
85
86 #endif // #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED