rtm.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright Oliver Kowalke 2017.
  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. //
  6. #ifndef BOOST_FIBER_DETAIL_RTM_H
  7. #define BOOST_FIBER_DETAIL_RTM_H
  8. #include <cstdint>
  9. #include <boost/assert.hpp>
  10. #include <boost/config.hpp>
  11. #include <boost/fiber/detail/config.hpp>
  12. #ifdef BOOST_HAS_ABI_HEADERS
  13. # include BOOST_ABI_PREFIX
  14. #endif
  15. namespace boost {
  16. namespace fibers {
  17. namespace detail {
  18. struct rtm_status {
  19. enum {
  20. none = 0,
  21. explicit_abort = 1 << 0,
  22. may_retry = 1 << 1,
  23. memory_conflict = 1 << 2,
  24. buffer_overflow = 1 << 3,
  25. debug_hit = 1 << 4,
  26. nested_abort = 1 << 5
  27. };
  28. static constexpr std::uint32_t success = ~std::uint32_t{ 0 };
  29. };
  30. static BOOST_FORCEINLINE
  31. std::uint32_t rtm_begin() noexcept {
  32. std::uint32_t result = rtm_status::success;
  33. __asm__ __volatile__
  34. (
  35. ".byte 0xc7,0xf8 ; .long 0"
  36. : "+a" (result)
  37. :
  38. : "memory"
  39. );
  40. return result;
  41. }
  42. static BOOST_FORCEINLINE
  43. void rtm_end() noexcept {
  44. __asm__ __volatile__
  45. (
  46. ".byte 0x0f,0x01,0xd5"
  47. :
  48. :
  49. : "memory"
  50. );
  51. }
  52. static BOOST_FORCEINLINE
  53. void rtm_abort_lock_not_free() noexcept {
  54. __asm__ __volatile__
  55. (
  56. ".byte 0xc6,0xf8,0xff"
  57. :
  58. :
  59. : "memory"
  60. );
  61. }
  62. static BOOST_FORCEINLINE
  63. bool rtm_test() noexcept {
  64. bool result;
  65. __asm__ __volatile__
  66. (
  67. ".byte 0x0f,0x01,0xd6; setz %0"
  68. : "=q" (result)
  69. :
  70. : "memory"
  71. );
  72. return result;
  73. }
  74. }}}
  75. #ifdef BOOST_HAS_ABI_HEADERS
  76. # include BOOST_ABI_SUFFIX
  77. #endif
  78. #endif // BOOST_FIBER_DETAIL_RTM_H