VLink  2.0.0
A high-performance communication middleware
vlink::SpinLock类 参考final

Adaptive spin lock satisfying the C++ Lockable named requirement. 更多...

#include <spin_lock.h>

vlink::SpinLock 的协作图:

Public 成员函数

 SpinLock () noexcept=default
 Constructs an unlocked spin lock. 更多...
 
 ~SpinLock () noexcept=default
 Destructor. Assumes the lock has already been released. 更多...
 
void lock () noexcept
 Acquires the lock, spinning with adaptive back-off until it becomes free. 更多...
 
bool try_lock () noexcept
 Attempts a single non-blocking acquire of the lock. 更多...
 
void unlock () noexcept
 Releases the lock with memory_order_release. 更多...
 

详细描述

Adaptive spin lock satisfying the C++ Lockable named requirement.

Cache-line aligned through alignas(64) to prevent false sharing. Composes with std::lock_guard, std::unique_lock and the supplied SpinLockGuard.

构造及析构函数说明

◆ SpinLock()

vlink::SpinLock::SpinLock ( )
defaultnoexcept

Constructs an unlocked spin lock.

◆ ~SpinLock()

vlink::SpinLock::~SpinLock ( )
defaultnoexcept

Destructor. Assumes the lock has already been released.

成员函数说明

◆ lock()

void vlink::SpinLock::lock ( )
inlinenoexcept

Acquires the lock, spinning with adaptive back-off until it becomes free.

Details

The inner loop alternates exchange attempts with relaxed-load spins. Each back-off rung doubles the spin budget from 8 up to 1024 then yields the CPU. After 50000 spins the back-off action switches to a 10 us sleep and a one-time warning is emitted.

警告
Recursive acquisition by the same thread deadlocks the lock.
函数调用图:

◆ try_lock()

bool vlink::SpinLock::try_lock ( )
inlinenoexcept

Attempts a single non-blocking acquire of the lock.

返回
true when the lock was successfully acquired.

◆ unlock()

void vlink::SpinLock::unlock ( )
inlinenoexcept

Releases the lock with memory_order_release.

May only be called by the thread that currently owns the lock.

这是这个函数的调用关系图:

该类的文档由以下文件生成: