VirtualBox

source: vbox/trunk/src/libs/boost-1.37.0/boost/detail/spinlock_pool.hpp@ 37808

Last change on this file since 37808 was 16204, checked in by vboxsync, 16 years ago

export the boost stuff required for Main

File size: 2.7 KB
Line 
1#ifndef BOOST_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
2#define 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 <boost/config.hpp>
25#include <boost/detail/spinlock.hpp>
26#include <cstddef>
27
28namespace boost
29{
30
31namespace detail
32{
33
34template< int I > class spinlock_pool
35{
36private:
37
38 static spinlock pool_[ 41 ];
39
40public:
41
42 static spinlock & spinlock_for( void const * pv )
43 {
44 std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41;
45 return pool_[ i ];
46 }
47
48 class scoped_lock
49 {
50 private:
51
52 spinlock & sp_;
53
54 scoped_lock( scoped_lock const & );
55 scoped_lock & operator=( scoped_lock const & );
56
57 public:
58
59 explicit scoped_lock( void const * pv ): sp_( spinlock_for( pv ) )
60 {
61 sp_.lock();
62 }
63
64 ~scoped_lock()
65 {
66 sp_.unlock();
67 }
68 };
69};
70
71template< int I > spinlock spinlock_pool< I >::pool_[ 41 ] =
72{
73 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
74 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
75 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
76 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
77 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
78 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
79 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
80 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
81 BOOST_DETAIL_SPINLOCK_INIT
82};
83
84} // namespace detail
85} // namespace boost
86
87#endif // #ifndef BOOST_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette