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

Private GIT Repository
8a62a90440acc63a288f4efca4653137b5a55e14
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / smart_ptr / detail / spinlock_pool.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED\r
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_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/spinlock_pool.hpp\r
12 //\r
13 //  Copyright (c) 2008 Peter Dimov\r
14 //\r
15 //  Distributed under the Boost Software License, Version 1.0.\r
16 //  See accompanying file LICENSE_1_0.txt or copy at\r
17 //  http://www.boost.org/LICENSE_1_0.txt)\r
18 //\r
19 //  spinlock_pool<0> is reserved for atomic<>, when/if it arrives\r
20 //  spinlock_pool<1> is reserved for shared_ptr reference counts\r
21 //  spinlock_pool<2> is reserved for shared_ptr atomic access\r
22 //\r
23 \r
24 #include <boost/config.hpp>\r
25 #include <boost/smart_ptr/detail/spinlock.hpp>\r
26 #include <cstddef>\r
27 \r
28 namespace boost\r
29 {\r
30 \r
31 namespace detail\r
32 {\r
33 \r
34 template< int I > class spinlock_pool\r
35 {\r
36 private:\r
37 \r
38     static spinlock pool_[ 41 ];\r
39 \r
40 public:\r
41 \r
42     static spinlock & spinlock_for( void const * pv )\r
43     {\r
44         std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41;\r
45         return pool_[ i ];\r
46     }\r
47 \r
48     class scoped_lock\r
49     {\r
50     private:\r
51 \r
52         spinlock & sp_;\r
53 \r
54         scoped_lock( scoped_lock const & );\r
55         scoped_lock & operator=( scoped_lock const & );\r
56 \r
57     public:\r
58 \r
59         explicit scoped_lock( void const * pv ): sp_( spinlock_for( pv ) )\r
60         {\r
61             sp_.lock();\r
62         }\r
63 \r
64         ~scoped_lock()\r
65         {\r
66             sp_.unlock();\r
67         }\r
68     };\r
69 };\r
70 \r
71 template< int I > spinlock spinlock_pool< I >::pool_[ 41 ] =\r
72 {\r
73     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
74     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
75     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
76     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
77     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
78     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
79     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
80     BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, \r
81     BOOST_DETAIL_SPINLOCK_INIT\r
82 };\r
83 \r
84 } // namespace detail\r
85 } // namespace boost\r
86 \r
87 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED\r