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

Private GIT Repository
920d67e1621b3b121afeff0cd0554486dd79d976
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / smart_ptr / detail / spinlock_nt.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED\r
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_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 //  Copyright (c) 2008 Peter Dimov\r
12 //\r
13 //  Distributed under the Boost Software License, Version 1.0.\r
14 //  See accompanying file LICENSE_1_0.txt or copy at\r
15 //  http://www.boost.org/LICENSE_1_0.txt)\r
16 //\r
17 \r
18 #include <boost/assert.hpp>\r
19 \r
20 namespace boost\r
21 {\r
22 \r
23 namespace detail\r
24 {\r
25 \r
26 class spinlock\r
27 {\r
28 public:\r
29 \r
30     bool locked_;\r
31 \r
32 public:\r
33 \r
34     inline bool try_lock()\r
35     {\r
36         if( locked_ )\r
37         {\r
38             return false;\r
39         }\r
40         else\r
41         {\r
42             locked_ = true;\r
43             return true;\r
44         }\r
45     }\r
46 \r
47     inline void lock()\r
48     {\r
49         BOOST_ASSERT( !locked_ );\r
50         locked_ = true;\r
51     }\r
52 \r
53     inline void unlock()\r
54     {\r
55         BOOST_ASSERT( locked_ );\r
56         locked_ = false;\r
57     }\r
58 \r
59 public:\r
60 \r
61     class scoped_lock\r
62     {\r
63     private:\r
64 \r
65         spinlock & sp_;\r
66 \r
67         scoped_lock( scoped_lock const & );\r
68         scoped_lock & operator=( scoped_lock const & );\r
69 \r
70     public:\r
71 \r
72         explicit scoped_lock( spinlock & sp ): sp_( sp )\r
73         {\r
74             sp.lock();\r
75         }\r
76 \r
77         ~scoped_lock()\r
78         {\r
79             sp_.unlock();\r
80         }\r
81     };\r
82 };\r
83 \r
84 } // namespace detail\r
85 } // namespace boost\r
86 \r
87 #define BOOST_DETAIL_SPINLOCK_INIT { false }\r
88 \r
89 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED\r