129 auto const thisThread = std::this_thread::get_id();
130 if (iState.load(std::memory_order_acquire) == spinlock_status::locked && iLockingThread.load(std::memory_order_acquire) == thisThread)
135 std::size_t collisions = 0;
138 std::size_t retries = 0;
139 while (spinlock_status::locked == iState.load(std::memory_order_relaxed))
141 if (BOOST_FIBERS_SPIN_BEFORE_SLEEP0 > retries)
146 else if (BOOST_FIBERS_SPIN_BEFORE_YIELD > retries)
148 static constexpr std::chrono::microseconds us0{ 0 };
149 std::this_thread::sleep_for(us0);
153 std::this_thread::yield();
156 if (spinlock_status::locked == iState.exchange(spinlock_status::locked, std::memory_order_acquire))
158 std::uniform_int_distribution< std::size_t > distribution
160 0,
static_cast<std::size_t
>(1) << (std::min)(collisions,
static_cast<std::size_t
>(BOOST_FIBERS_CONTENTION_WINDOW_THRESHOLD))
162 const std::size_t z = distribution(iGenerator);
164 for (std::size_t i = 0; i < z; ++i)
171 iLockingThread.store(thisThread);
187 auto const thisThread = std::this_thread::get_id();
188 if (iState.load(std::memory_order_acquire) == spinlock_status::locked && iLockingThread.load(std::memory_order_acquire) == thisThread)
193 bool locked = (spinlock_status::unlocked == iState.exchange(spinlock_status::locked, std::memory_order_acquire));
196 iLockingThread.store(thisThread);