spinlock_pool.hpp
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 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  boost/detail/spinlock_pool.hpp
00012 //
00013 //  Copyright (c) 2008 Peter Dimov
00014 //
00015 //  Distributed under the Boost Software License, Version 1.0.
00016 //  See accompanying file LICENSE_1_0.txt or copy at
00017 //  http://www.boost.org/LICENSE_1_0.txt)
00018 //
00019 //  spinlock_pool<0> is reserved for atomic<>, when/if it arrives
00020 //  spinlock_pool<1> is reserved for shared_ptr reference counts
00021 //  spinlock_pool<2> is reserved for shared_ptr atomic access
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 } // namespace detail
00085 } // namespace boost
00086 
00087 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29