1 2 // Copyright Oliver Kowalke 2013. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef BOOST_FIBERS_SPINLOCK_H 8 #define BOOST_FIBERS_SPINLOCK_H 9 10 #include <boost/config.hpp> 11 12 #include <boost/fiber/detail/config.hpp> 13 14 #if !defined(BOOST_FIBERS_NO_ATOMICS) 15 # include <mutex> 16 # include <boost/fiber/detail/spinlock_ttas_adaptive.hpp> 17 # include <boost/fiber/detail/spinlock_ttas.hpp> 18 # if defined(BOOST_FIBERS_HAS_FUTEX) 19 # include <boost/fiber/detail/spinlock_ttas_adaptive_futex.hpp> 20 # include <boost/fiber/detail/spinlock_ttas_futex.hpp> 21 # endif 22 # if defined(BOOST_USE_TSX) 23 # include <boost/fiber/detail/spinlock_rtm.hpp> 24 # endif 25 #endif 26 27 #ifdef BOOST_HAS_ABI_HEADERS 28 # include BOOST_ABI_PREFIX 29 #endif 30 31 namespace boost { 32 namespace fibers { 33 namespace detail { 34 35 #if defined(BOOST_FIBERS_NO_ATOMICS) 36 struct spinlock { spinlockboost::fibers::detail::spinlock37 constexpr spinlock() noexcept {} lockboost::fibers::detail::spinlock38 void lock() noexcept {} unlockboost::fibers::detail::spinlock39 void unlock() noexcept {} 40 }; 41 42 struct spinlock_lock { spinlock_lockboost::fibers::detail::spinlock_lock43 constexpr spinlock_lock( spinlock &) noexcept {} lockboost::fibers::detail::spinlock_lock44 void lock() noexcept {} unlockboost::fibers::detail::spinlock_lock45 void unlock() noexcept {} 46 }; 47 #else 48 # if defined(BOOST_FIBERS_SPINLOCK_STD_MUTEX) 49 using spinlock = std::mutex; 50 # elif defined(BOOST_FIBERS_SPINLOCK_TTAS_FUTEX) 51 # if defined(BOOST_USE_TSX) 52 using spinlock = spinlock_rtm< spinlock_ttas_futex >; 53 # else 54 using spinlock = spinlock_ttas_futex; 55 # endif 56 # elif defined(BOOST_FIBERS_SPINLOCK_TTAS_ADAPTIVE_FUTEX) 57 # if defined(BOOST_USE_TSX) 58 using spinlock = spinlock_rtm< spinlock_ttas_adaptive_futex >; 59 # else 60 using spinlock = spinlock_ttas_adaptive_futex; 61 # endif 62 # elif defined(BOOST_FIBERS_SPINLOCK_TTAS_ADAPTIVE) 63 # if defined(BOOST_USE_TSX) 64 using spinlock = spinlock_rtm< spinlock_ttas_adaptive >; 65 # else 66 using spinlock = spinlock_ttas_adaptive; 67 # endif 68 # else 69 # if defined(BOOST_USE_TSX) 70 using spinlock = spinlock_rtm< spinlock_ttas >; 71 # else 72 using spinlock = spinlock_ttas; 73 # endif 74 # endif 75 using spinlock_lock = std::unique_lock< spinlock >; 76 #endif 77 78 }}} 79 80 #ifdef BOOST_HAS_ABI_HEADERS 81 # include BOOST_ABI_SUFFIX 82 #endif 83 84 #endif // BOOST_FIBERS_SPINLOCK_H 85