Go to the documentation of this file.00001 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
00003
00004
00005
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <boost/config.hpp>
00025 #include <boost/smart_ptr/detail/spinlock.hpp>
00026 #include <cstddef>
00027
00028 namespace boost
00029 {
00030
00031 namespace detail
00032 {
00033
00034 template< int I > class spinlock_pool
00035 {
00036 private:
00037
00038 static spinlock pool_[ 41 ];
00039
00040 public:
00041
00042 static spinlock & spinlock_for( void const * pv )
00043 {
00044 std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41;
00045 return pool_[ i ];
00046 }
00047
00048 class scoped_lock
00049 {
00050 private:
00051
00052 spinlock & sp_;
00053
00054 scoped_lock( scoped_lock const & );
00055 scoped_lock & operator=( scoped_lock const & );
00056
00057 public:
00058
00059 explicit scoped_lock( void const * pv ): sp_( spinlock_for( pv ) )
00060 {
00061 sp_.lock();
00062 }
00063
00064 ~scoped_lock()
00065 {
00066 sp_.unlock();
00067 }
00068 };
00069 };
00070
00071 template< int I > spinlock spinlock_pool< I >::pool_[ 41 ] =
00072 {
00073 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00074 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00075 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00076 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00077 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00078 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00079 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00080 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
00081 BOOST_DETAIL_SPINLOCK_INIT
00082 };
00083
00084 }
00085 }
00086
00087 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED