annotate DEPENDENCIES/generic/include/boost/smart_ptr/detail/spinlock_pool.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
Chris@16 2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED
Chris@16 3
Chris@16 4 // MS compatible compilers support #pragma once
Chris@16 5
Chris@16 6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
Chris@16 7 # pragma once
Chris@16 8 #endif
Chris@16 9
Chris@16 10 //
Chris@16 11 // boost/detail/spinlock_pool.hpp
Chris@16 12 //
Chris@16 13 // Copyright (c) 2008 Peter Dimov
Chris@16 14 //
Chris@16 15 // Distributed under the Boost Software License, Version 1.0.
Chris@16 16 // See accompanying file LICENSE_1_0.txt or copy at
Chris@16 17 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 18 //
Chris@16 19 // spinlock_pool<0> is reserved for atomic<>, when/if it arrives
Chris@16 20 // spinlock_pool<1> is reserved for shared_ptr reference counts
Chris@16 21 // spinlock_pool<2> is reserved for shared_ptr atomic access
Chris@16 22 //
Chris@16 23
Chris@16 24 #include <boost/config.hpp>
Chris@16 25 #include <boost/smart_ptr/detail/spinlock.hpp>
Chris@16 26 #include <cstddef>
Chris@16 27
Chris@16 28 namespace boost
Chris@16 29 {
Chris@16 30
Chris@16 31 namespace detail
Chris@16 32 {
Chris@16 33
Chris@101 34 template< int M > class spinlock_pool
Chris@16 35 {
Chris@16 36 private:
Chris@16 37
Chris@16 38 static spinlock pool_[ 41 ];
Chris@16 39
Chris@16 40 public:
Chris@16 41
Chris@16 42 static spinlock & spinlock_for( void const * pv )
Chris@16 43 {
Chris@16 44 #if defined(__VMS) && __INITIAL_POINTER_SIZE == 64
Chris@16 45 std::size_t i = reinterpret_cast< unsigned long long >( pv ) % 41;
Chris@16 46 #else
Chris@16 47 std::size_t i = reinterpret_cast< std::size_t >( pv ) % 41;
Chris@16 48 #endif
Chris@16 49 return pool_[ i ];
Chris@16 50 }
Chris@16 51
Chris@16 52 class scoped_lock
Chris@16 53 {
Chris@16 54 private:
Chris@16 55
Chris@16 56 spinlock & sp_;
Chris@16 57
Chris@16 58 scoped_lock( scoped_lock const & );
Chris@16 59 scoped_lock & operator=( scoped_lock const & );
Chris@16 60
Chris@16 61 public:
Chris@16 62
Chris@16 63 explicit scoped_lock( void const * pv ): sp_( spinlock_for( pv ) )
Chris@16 64 {
Chris@16 65 sp_.lock();
Chris@16 66 }
Chris@16 67
Chris@16 68 ~scoped_lock()
Chris@16 69 {
Chris@16 70 sp_.unlock();
Chris@16 71 }
Chris@16 72 };
Chris@16 73 };
Chris@16 74
Chris@101 75 template< int M > spinlock spinlock_pool< M >::pool_[ 41 ] =
Chris@16 76 {
Chris@16 77 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 78 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 79 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 80 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 81 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 82 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 83 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 84 BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT, BOOST_DETAIL_SPINLOCK_INIT,
Chris@16 85 BOOST_DETAIL_SPINLOCK_INIT
Chris@16 86 };
Chris@16 87
Chris@16 88 } // namespace detail
Chris@16 89 } // namespace boost
Chris@16 90
Chris@16 91 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_POOL_HPP_INCLUDED