Chris@16: #ifndef BOOST_ATOMIC_DETAIL_LOCKPOOL_HPP Chris@16: #define BOOST_ATOMIC_DETAIL_LOCKPOOL_HPP Chris@16: Chris@16: // Copyright (c) 2011 Helge Bahmann 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: #include Chris@16: #include Chris@16: #ifndef BOOST_ATOMIC_FLAG_LOCK_FREE Chris@16: #include Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace atomics { Chris@16: namespace detail { Chris@16: Chris@16: #ifndef BOOST_ATOMIC_FLAG_LOCK_FREE Chris@16: Chris@16: class lockpool Chris@16: { Chris@16: public: Chris@16: typedef boost::detail::lightweight_mutex lock_type; Chris@16: class scoped_lock : Chris@16: public lock_type::scoped_lock Chris@16: { Chris@16: typedef lock_type::scoped_lock base_type; Chris@16: Chris@16: public: Chris@16: explicit scoped_lock(const volatile void * addr) : base_type(get_lock_for(addr)) Chris@16: { Chris@16: } Chris@16: Chris@16: BOOST_DELETED_FUNCTION(scoped_lock(scoped_lock const&)) Chris@16: BOOST_DELETED_FUNCTION(scoped_lock& operator=(scoped_lock const&)) Chris@16: }; Chris@16: Chris@16: private: Chris@16: static BOOST_ATOMIC_DECL lock_type& get_lock_for(const volatile void * addr); Chris@16: }; Chris@16: Chris@16: #else Chris@16: Chris@16: class lockpool Chris@16: { Chris@16: public: Chris@16: typedef atomic_flag lock_type; Chris@16: Chris@16: class scoped_lock Chris@16: { Chris@16: private: Chris@16: atomic_flag& flag_; Chris@16: Chris@16: public: Chris@16: explicit Chris@16: scoped_lock(const volatile void * addr) : flag_(get_lock_for(addr)) Chris@16: { Chris@16: for (; flag_.test_and_set(memory_order_acquire);) Chris@16: { Chris@16: #if defined(BOOST_ATOMIC_X86_PAUSE) Chris@16: BOOST_ATOMIC_X86_PAUSE(); Chris@16: #endif Chris@16: } Chris@16: } Chris@16: Chris@16: ~scoped_lock(void) Chris@16: { Chris@16: flag_.clear(memory_order_release); Chris@16: } Chris@16: Chris@16: BOOST_DELETED_FUNCTION(scoped_lock(const scoped_lock &)) Chris@16: BOOST_DELETED_FUNCTION(scoped_lock& operator=(const scoped_lock &)) Chris@16: }; Chris@16: Chris@16: private: Chris@16: static BOOST_ATOMIC_DECL lock_type& get_lock_for(const volatile void * addr); Chris@16: }; Chris@16: Chris@16: #endif Chris@16: Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: #endif