File indexing completed on 2025-01-18 09:51:43
0001 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
0003
0004
0005
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <boost/config.hpp>
0025 #include <boost/smart_ptr/detail/spinlock.hpp>
0026 #include <cstddef>
0027
0028 namespace boost
0029 {
0030
0031 namespace detail
0032 {
0033
0034 template< int M > class spinlock_pool
0035 {
0036 private:
0037
0038 static spinlock pool_[ 41 ];
0039
0040 public:
0041
0042 static spinlock & spinlock_for( void const * pv )
0043 {
0044 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
0045 std::size_t i = reinterpret_cast< unsigned long long >( pv ) % 41;
0046 #else
0047 std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41;
0048 #endif
0049 return pool_[ i ];
0050 }
0051
0052 class scoped_lock
0053 {
0054 private:
0055
0056 spinlock & sp_;
0057
0058 scoped_lock( scoped_lock const & );
0059 scoped_lock & operator=( scoped_lock const & );
0060
0061 public:
0062
0063 explicit scoped_lock( void const * pv ): sp_( spinlock_for( pv ) )
0064 {
0065 sp_.lock();
0066 }
0067
0068 ~scoped_lock()
0069 {
0070 sp_.unlock();
0071 }
0072 };
0073 };
0074
0075 template< int M > spinlock spinlock_pool< M >::pool_[ 41 ] =
0076 {
0077 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0078 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0079 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0080 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0081 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0082 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0083 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0084 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
0085 BOOST_DETAIL_SPINLOCK_INIT
0086 };
0087
0088 }
0089 }
0090
0091 #endif