VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::SpinLock类 参考final

Adaptive, cache-line-aligned spin lock. 更多...

#include <spin_lock.h>

vlink::SpinLock 的协作图:

Public 成员函数

 SpinLock () noexcept=default
 Default constructor. Initialises the flag to false (unlocked).
 ~SpinLock () noexcept=default
 Destructor.
void lock () noexcept
 Acquires the lock, spinning until successful.
bool try_lock () noexcept
 Attempts to acquire the lock without blocking.
void unlock () noexcept
 Releases the lock.

详细描述

Adaptive, cache-line-aligned spin lock.

Implements the Lockable named requirement: lock(), try_lock(), and unlock(). Can be used directly with std::lock_guard.

构造及析构函数说明

◆ SpinLock()

vlink::SpinLock::SpinLock ( )
defaultnoexcept

Default constructor. Initialises the flag to false (unlocked).

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

◆ ~SpinLock()

vlink::SpinLock::~SpinLock ( )
defaultnoexcept

Destructor.

函数调用图:

成员函数说明

◆ lock()

void vlink::SpinLock::lock ( )
inlinenoexcept

Acquires the lock, spinning until successful.

Details

Uses an exponential back-off strategy to reduce bus contention:

  • Spins with load(relaxed) for up to backoff iterations.
  • Calls Utils::yield_cpu() (PAUSE/WFE/yield) when backoff is reached.
  • Back-off doubles each round up to 1024.
  • After 50000 total spins, logs an error and sleeps 10 us.
警告
This function must not be called recursively from the same thread; doing so will cause an infinite deadlock.
函数调用图:
这是这个函数的调用关系图:

◆ try_lock()

bool vlink::SpinLock::try_lock ( )
inlinenoexcept

Attempts to acquire the lock without blocking.

Performs a single exchange(true, acquire). Returns immediately regardless of whether the lock was acquired.

返回
true if the lock was successfully acquired, false if it was already held by another thread.
这是这个函数的调用关系图:

◆ unlock()

void vlink::SpinLock::unlock ( )
inlinenoexcept

Releases the lock.

Stores false with release memory order. Must only be called by the thread that successfully called lock() or try_lock().

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

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