20  std::atomic_flag lock_flag;
 
   26  bool try_lock() { 
return !lock_flag.test_and_set(std::memory_order_acquire); }
 
   30    for (
unsigned int i = 1; !
try_lock(); ++i) {
 
   31      if ((i & 0xff) == 0) {
 
   32        std::this_thread::yield();
 
 
   38  void unlock() { lock_flag.clear(std::memory_order_release); }
 
 
   47  std::atomic<std::thread::id> owner_thread_id{std::thread::id{}};
 
   48  int32_t recursive_counter{0};
 
   49  std::atomic_flag lock_flag;
 
   56    if (!lock_flag.test_and_set(std::memory_order_acquire)) {
 
   57      owner_thread_id.store(std::this_thread::get_id(),
 
   58                            std::memory_order_release);
 
   60      if (owner_thread_id.load(std::memory_order_acquire) !=
 
   61          std::this_thread::get_id()) {
 
 
   71    for (
unsigned int i = 1; !
try_lock(); ++i) {
 
   72      if ((i & 0xffff) == 0) {
 
   73        std::this_thread::yield();
 
 
   80    assert(owner_thread_id.load(std::memory_order_acquire) ==
 
   81           std::this_thread::get_id());
 
   82    assert(recursive_counter > 0);
 
   84    if (--recursive_counter == 0) {
 
   85      owner_thread_id.store(std::thread::id{}, std::memory_order_release);
 
   86      lock_flag.clear(std::memory_order_release);
 
 
 
   97  std::atomic<std::thread::id> owner_thread_id{std::thread::id{}};
 
   98  int32_t recursive_counter{0};
 
  103    auto owner = std::thread::id{};
 
  104    auto us = std::this_thread::get_id();
 
  105    if (!owner_thread_id.compare_exchange_weak(owner, us,
 
  106                                               std::memory_order_acquire)) {
 
 
  117    for (
unsigned int i = 1; !
try_lock(); ++i) {
 
  118      if ((i & 0xffff) == 0) {
 
  119        std::this_thread::yield();
 
 
  126    assert(owner_thread_id.load(std::memory_order_acquire) ==
 
  127           std::this_thread::get_id());
 
  128    assert(recursive_counter > 0);
 
  130    if (--recursive_counter == 0) {
 
  131      owner_thread_id.store(std::thread::id{}, std::memory_order_release);
 
 
 
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
Definition Compiler.h:277
A recursive spinlock mutex.
Definition spinlock.h:46
LLVM_ATTRIBUTE_ALWAYS_INLINE void unlock()
Definition spinlock.h:79
recursive_spinlock1() noexcept
Definition spinlock.h:52
LLVM_ATTRIBUTE_ALWAYS_INLINE void lock()
Definition spinlock.h:70
LLVM_ATTRIBUTE_ALWAYS_INLINE bool try_lock()
Definition spinlock.h:55
A recursive spinlock mutex.
Definition spinlock.h:96
LLVM_ATTRIBUTE_ALWAYS_INLINE bool try_lock()
Definition spinlock.h:102
LLVM_ATTRIBUTE_ALWAYS_INLINE void lock()
Definition spinlock.h:116
LLVM_ATTRIBUTE_ALWAYS_INLINE void unlock()
Definition spinlock.h:125
A spinlock mutex.
Definition spinlock.h:19
LLVM_ATTRIBUTE_ALWAYS_INLINE void lock()
Definition spinlock.h:29
spinlock() noexcept
Definition spinlock.h:23
LLVM_ATTRIBUTE_ALWAYS_INLINE bool try_lock()
Definition spinlock.h:26
LLVM_ATTRIBUTE_ALWAYS_INLINE void unlock()
Definition spinlock.h:38
Foonathan namespace.
Definition ntcore_cpp.h:26
recursive_spinlock1 recursive_spinlock
Definition spinlock.h:141