spinlock.hpp 2.1 KB

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