]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/smart_ptr/detail/lwm_pthreads.hpp
Logo AND Algorithmique Numérique Distribuée

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