CGraph
Public Member Functions | Private Attributes | List of all members
USpinLock Class Reference

基于std::atomic_flag实现的用户态自旋锁,std::atomic_flag只有true/false两种状态; USpinLock提供以下三个方法:lock为忙等,tryLock为单次尝试,unlock为解锁; (基于std::atomic_flag实现的用户态自旋锁是一种采用的做法,) More...

#include <USpinLock.h>

Inheritance diagram for USpinLock:
Inheritance graph
[legend]
Collaboration diagram for USpinLock:
Collaboration graph
[legend]

Public Member Functions

CVoid lock ()
 
CVoid unlock ()
 
CBool tryLock ()
 
- Public Member Functions inherited from CObject
 CObject ()=default
 
virtual CStatus init ()
 
virtual CStatus destroy ()
 
virtual ~CObject ()=default
 

Private Attributes

std::atomic_flag flag_ = ATOMIC_FLAG_INIT
 

Additional Inherited Members

- Protected Member Functions inherited from UThreadObject
CStatus run () override
 
- Protected Member Functions inherited from UtilsObject
CStatus run () override
 

Detailed Description

基于std::atomic_flag实现的用户态自旋锁,std::atomic_flag只有true/false两种状态; USpinLock提供以下三个方法:lock为忙等,tryLock为单次尝试,unlock为解锁; (基于std::atomic_flag实现的用户态自旋锁是一种采用的做法,)

Member Function Documentation

◆ lock()

CVoid USpinLock::lock ( )
inline

加锁

◆ tryLock()

CBool USpinLock::tryLock ( )
inline

尝试加锁。若未加锁,会上锁

Returns

◆ unlock()

CVoid USpinLock::unlock ( )
inline

解锁

Member Data Documentation

◆ flag_

std::atomic_flag USpinLock::flag_ = ATOMIC_FLAG_INIT
private

The documentation for this class was generated from the following file: