Chris@16: #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED Chris@16: #define BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: // Chris@16: // boost/detail/spinlock_pool.hpp Chris@16: // Chris@16: // Copyright (c) 2008 Peter Dimov Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // spinlock_pool<0> is reserved for atomic<>, when/if it arrives Chris@16: // spinlock_pool<1> is reserved for shared_ptr reference counts Chris@16: // spinlock_pool<2> is reserved for shared_ptr atomic access Chris@16: // Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: Chris@101: template< int M > class spinlock_pool Chris@16: { Chris@16: private: Chris@16: Chris@16: static spinlock pool_[ 41 ]; Chris@16: Chris@16: public: Chris@16: Chris@16: static spinlock & spinlock_for( void const * pv ) Chris@16: { Chris@16: #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64 Chris@16: std::size_t i = reinterpret_cast< unsigned long long >( pv ) % 41; Chris@16: #else Chris@16: std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41; Chris@16: #endif Chris@16: return pool_[ i ]; Chris@16: } Chris@16: Chris@16: class scoped_lock Chris@16: { Chris@16: private: Chris@16: Chris@16: spinlock & sp_; Chris@16: Chris@16: scoped_lock( scoped_lock const & ); Chris@16: scoped_lock & operator=( scoped_lock const & ); Chris@16: Chris@16: public: Chris@16: Chris@16: explicit scoped_lock( void const * pv ): sp_( spinlock_for( pv ) ) Chris@16: { Chris@16: sp_.lock(); Chris@16: } Chris@16: Chris@16: ~scoped_lock() Chris@16: { Chris@16: sp_.unlock(); Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@101: template< int M > spinlock spinlock_pool< M >::pool_[ 41 ] = Chris@16: { Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, Chris@16: BOOST_DETAIL_SPINLOCK_INIT Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace boost Chris@16: Chris@16: #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED