NVIDIA DeepStream SDK API Reference

9.2 Release
common::SpinLockMutex Class Reference

Detailed Description

A Mutex which uses atomic flags and spin-locks instead of halting threads.

This mutex uses an incremental back-off strategy with the following phases:

  1. A tight spin-lock loop (pending: using hardware PAUSE/YIELD instructions)
  2. A loop where the current thread yields control after checking the lock.
  3. Issuing a thread-sleep call before starting back in phase 1.

This is meant to give a good balance of perofrmance and CPU consumption in practice.

This mutex uses an incremental back-off strategy with the following phases:

  1. A tight spin-lock loop (pending: using hardware PAUSE/YIELD instructions)
  2. A loop where the current thread yields control after checking the lock.
  3. Issuing a thread-sleep call before starting back in phase 1.

This is meant to give a good balance of perofrmance and CPU consumption in practice.

This class implements the BasicLockable specification: https://en.cppreference.com/w/cpp/named_req/BasicLockable

Definition at line 52 of file includes/opentelemetry/common/spin_lock_mutex.h.

Public Member Functions

 SpinLockMutex () noexcept
 
 ~SpinLockMutex () noexcept=default
 
 SpinLockMutex (const SpinLockMutex &)=delete
 
SpinLockMutex & operator= (const SpinLockMutex &)=delete
 
bool try_lock () noexcept
 Attempts to lock the mutex. More...
 
void lock () noexcept
 Blocks until a lock can be obtained for the current thread. More...
 
void unlock () noexcept
 Releases the lock held by the execution agent. More...
 
 SpinLockMutex () noexcept
 
 ~SpinLockMutex () noexcept=default
 
 SpinLockMutex (const SpinLockMutex &)=delete
 
SpinLockMutex & operator= (const SpinLockMutex &)=delete
 
bool try_lock () noexcept
 Attempts to lock the mutex. More...
 
void lock () noexcept
 Blocks until a lock can be obtained for the current thread. More...
 
void unlock () noexcept
 Releases the lock held by the execution agent. More...
 

Static Public Member Functions

static void fast_yield () noexcept
 
static void fast_yield () noexcept
 

Constructor & Destructor Documentation

◆ SpinLockMutex() [1/4]

common::SpinLockMutex::SpinLockMutex ( )
inlinenoexcept

◆ ~SpinLockMutex() [1/2]

common::SpinLockMutex::~SpinLockMutex ( )
defaultnoexcept

◆ SpinLockMutex() [2/4]

common::SpinLockMutex::SpinLockMutex ( const SpinLockMutex &  )
delete

◆ SpinLockMutex() [3/4]

common::SpinLockMutex::SpinLockMutex ( )
inlinenoexcept

◆ ~SpinLockMutex() [2/2]

common::SpinLockMutex::~SpinLockMutex ( )
defaultnoexcept

◆ SpinLockMutex() [4/4]

common::SpinLockMutex::SpinLockMutex ( const SpinLockMutex &  )
delete

Member Function Documentation

◆ fast_yield() [1/2]

static void common::SpinLockMutex::fast_yield ( )
inlinestaticnoexcept

Definition at line 60 of file includes/opentelemetry/common/spin_lock_mutex.h.

Referenced by lock().

◆ fast_yield() [2/2]

static void common::SpinLockMutex::fast_yield ( )
inlinestaticnoexcept

◆ lock() [1/2]

void common::SpinLockMutex::lock ( )
inlinenoexcept

Blocks until a lock can be obtained for the current thread.

This mutex will spin the current CPU waiting for the lock to be available. This can have decent performance in scenarios where there is low lock contention and lock-holders achieve their work quickly. It degrades in scenarios where locked tasks take a long time.

Definition at line 96 of file includes/opentelemetry/common/spin_lock_mutex.h.

References fast_yield(), common::SPINLOCK_FAST_ITERATIONS, common::SPINLOCK_SLEEP_MS, and try_lock().

◆ lock() [2/2]

void common::SpinLockMutex::lock ( )
inlinenoexcept

Blocks until a lock can be obtained for the current thread.

This mutex will spin the current CPU waiting for the lock to be available. This can have decent performance in scenarios where there is low lock contention and lock-holders achieve their work quickly. It degrades in scenarios where locked tasks take a long time.

Definition at line 96 of file 9.2/includes/opentelemetry/common/spin_lock_mutex.h.

References fast_yield(), common::SPINLOCK_FAST_ITERATIONS, common::SPINLOCK_SLEEP_MS, and try_lock().

◆ operator=() [1/2]

SpinLockMutex& common::SpinLockMutex::operator= ( const SpinLockMutex &  )
delete

◆ operator=() [2/2]

SpinLockMutex& common::SpinLockMutex::operator= ( const SpinLockMutex &  )
delete

◆ try_lock() [1/2]

bool common::SpinLockMutex::try_lock ( )
inlinenoexcept

Attempts to lock the mutex.

Return immediately with true (success) or false (failure).

Definition at line 83 of file 9.2/includes/opentelemetry/common/spin_lock_mutex.h.

◆ try_lock() [2/2]

bool common::SpinLockMutex::try_lock ( )
inlinenoexcept

Attempts to lock the mutex.

Return immediately with true (success) or false (failure).

Definition at line 83 of file includes/opentelemetry/common/spin_lock_mutex.h.

Referenced by lock().

◆ unlock() [1/2]

void common::SpinLockMutex::unlock ( )
inlinenoexcept

Releases the lock held by the execution agent.

Throws no exceptions.

Definition at line 126 of file 9.2/includes/opentelemetry/common/spin_lock_mutex.h.

◆ unlock() [2/2]

void common::SpinLockMutex::unlock ( )
inlinenoexcept

Releases the lock held by the execution agent.

Throws no exceptions.

Definition at line 126 of file includes/opentelemetry/common/spin_lock_mutex.h.


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