]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/lwm_pthreads.hpp
2002-05-24 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[lyx.git] / boost / boost / detail / lwm_pthreads.hpp
1 #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
2 #define BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED
3
4 #if _MSC_VER >= 1020
5 #pragma once
6 #endif
7
8 //
9 //  boost/detail/lwm_pthreads.hpp
10 //
11 //  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
12 //
13 //  Permission to copy, use, modify, sell and distribute this software
14 //  is granted provided this copyright notice appears in all copies.
15 //  This software is provided "as is" without express or implied
16 //  warranty, and with no claim as to its suitability for any purpose.
17 //
18
19 #include <pthread.h>
20
21 namespace boost
22 {
23
24 namespace detail
25 {
26
27 class lightweight_mutex
28 {
29 private:
30
31     pthread_mutex_t m_;
32
33     lightweight_mutex(lightweight_mutex const &);
34     lightweight_mutex & operator=(lightweight_mutex const &);
35
36 public:
37
38     lightweight_mutex()
39     {
40         pthread_mutex_init(&m_, 0);
41     }
42
43     ~lightweight_mutex()
44     {
45         pthread_mutex_destroy(&m_);
46     }
47
48     class scoped_lock;
49     friend class scoped_lock;
50
51     class scoped_lock
52     {
53     private:
54
55         pthread_mutex_t & m_;
56
57         scoped_lock(scoped_lock const &);
58         scoped_lock & operator=(scoped_lock const &);
59
60     public:
61
62         scoped_lock(lightweight_mutex & m): m_(m.m_)
63         {
64             pthread_mutex_lock(&m_);
65         }
66
67         ~scoped_lock()
68         {
69             pthread_mutex_unlock(&m_);
70         }
71     };
72 };
73
74 } // namespace detail
75
76 } // namespace boost
77
78 #endif // #ifndef BOOST_DETAIL_LWM_PTHREADS_HPP_INCLUDED