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