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)
7 #ifndef BOOST_FIBERS_SPINLOCK_H
8 #define BOOST_FIBERS_SPINLOCK_H
10 #include <boost/config.hpp>
12 #include <boost/fiber/detail/config.hpp>
14 #if !defined(BOOST_FIBERS_NO_ATOMICS)
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>
22 # if defined(BOOST_USE_TSX)
23 # include <boost/fiber/detail/spinlock_rtm.hpp>
27 #ifdef BOOST_HAS_ABI_HEADERS
28 # include BOOST_ABI_PREFIX
35 #if defined(BOOST_FIBERS_NO_ATOMICS)
37 constexpr spinlock() noexcept {}
38 void lock() noexcept {}
39 void unlock() noexcept {}
42 struct spinlock_lock {
43 constexpr spinlock_lock( spinlock &) noexcept {}
44 void lock() noexcept {}
45 void unlock() noexcept {}
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 >;
54 using spinlock = spinlock_ttas_futex;
56 # elif defined(BOOST_FIBERS_SPINLOCK_TTAS_ADAPTIVE_FUTEX)
57 # if defined(BOOST_USE_TSX)
58 using spinlock = spinlock_rtm< spinlock_ttas_adaptive_futex >;
60 using spinlock = spinlock_ttas_adaptive_futex;
62 # elif defined(BOOST_FIBERS_SPINLOCK_TTAS_ADAPTIVE)
63 # if defined(BOOST_USE_TSX)
64 using spinlock = spinlock_rtm< spinlock_ttas_adaptive >;
66 using spinlock = spinlock_ttas_adaptive;
69 # if defined(BOOST_USE_TSX)
70 using spinlock = spinlock_rtm< spinlock_ttas >;
72 using spinlock = spinlock_ttas;
75 using spinlock_lock = std::unique_lock< spinlock >;
80 #ifdef BOOST_HAS_ABI_HEADERS
81 # include BOOST_ABI_SUFFIX
84 #endif // BOOST_FIBERS_SPINLOCK_H