8#ifndef INCLUDED_BSLS_SPINLOCK
9#define INCLUDED_BSLS_SPINLOCK
309#include <bsls_assert.h>
316#if (BSLS_COMPILERFEATURES_CPLUSPLUS < 201703L)
317#define BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
325#ifdef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
326#define BSLS_SPINLOCK_UNLOCKED { {0} }
328#define BSLS_SPINLOCK_UNLOCKED (::BloombergLP::bsls::SpinLock::s_unlocked)
331#ifdef BSLS_PLATFORM_OS_WINDOWS
332typedef unsigned long DWORD;
336 __declspec(dllimport)
void __stdcall Sleep(
337 DWORD dwMilliseconds);
339 __declspec(dllimport) DWORD __stdcall SleepEx(
340 DWORD dwMilliseconds,
385#ifdef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
408 static void doBackoff(
int *count);
417 static void sleepMillis(
int milliseconds);
426#ifdef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
439 AtomicOperations::AtomicTypes::Int
d_state;
444#ifndef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
455#ifdef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
488 int tryLock(
int numRetries = 0);
541#ifndef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
542constexpr SpinLock::SpinLock()
547constexpr SpinLock::SpinLock(
const SpinLock_MemberInitializer&)
555void SpinLock::doBackoff(
int *count) {
568void SpinLock::sleepMillis(
int milliseconds)
570#ifdef BSLS_PLATFORM_OS_WINDOWS
571 ::Sleep(milliseconds);
575 naptime.tv_nsec = 1000 * 1000 * milliseconds;
576 nanosleep(&naptime, 0);
581void SpinLock::yield() {
582#ifdef BSLS_PLATFORM_OS_WINDOWS
640 }
while (numRetries--);
680#undef BSLS_SPINLOCK_USES_AGGREGATE_INITIALIZATION
Definition bsls_spinlock.h:502
SpinLock * release()
Definition bsls_spinlock.h:671
~SpinLockGuard()
Definition bsls_spinlock.h:662
Definition bsls_spinlock.h:362
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_DELETED
Definition bsls_keyword.h:609
Definition bdlt_iso8601util.h:691
static int getIntAcquire(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1528
static void setIntRelease(AtomicTypes::Int *atomicInt, int value)
Definition bsls_atomicoperations.h:1558
static int getInt(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1522
static int swapIntAcqRel(AtomicTypes::Int *atomicInt, int swapValue)
Definition bsls_atomicoperations.h:1570
Definition bsls_spinlock.h:381
void lockWithBackoff()
Definition bsls_spinlock.h:596
int tryLock(int numRetries=0)
Definition bsls_spinlock.h:628
void lockWithoutBackoff()
Definition bsls_spinlock.h:613
static const SpinLock s_unlocked
Definition bsls_spinlock.h:456
void lock()
Definition bsls_spinlock.h:591
void unlock()
Definition bsls_spinlock.h:645
AtomicOperations::AtomicTypes::Int d_state
Definition bsls_spinlock.h:433