ScopedLock Class Reference

#include <spinlock.h>

Detailed Description

The ScopedLock class acquires a lock to the specified mutex upon creation and releases this upon destruction (usually at the end of a code block). This simplifies cases where your code contains many return statements where you'd otherwise have to manually unlock before returning. Only use ScopedLock for a short block of your code. Do not use ScopedLock mindlessly at the beginning of a function! This will block all other threads for the whole runtime of the function which usually is much longer that required.

THREADSAFE.

See also
SpinLock

Public Member Functions

 ScopedLock (Spinlock &lock)
 
 ScopedLock (ScopedLock &&src)
 
 ~ScopedLock ()
 

Private Member Functions

 MAXON_DISALLOW_COPY_AND_ASSIGN (ScopedLock)
 

Private Attributes

Spinlock_lock
 

Constructor & Destructor Documentation

◆ ScopedLock() [1/2]

ScopedLock ( Spinlock lock)
explicit

Acquires the specified lock (and releases it upon destruction).

Parameters
[in]lockThe lock to be acquired.

◆ ScopedLock() [2/2]

ScopedLock ( ScopedLock &&  src)

Move constructor.

◆ ~ScopedLock()

~ScopedLock ( )

Releases the lock on destruction.

Member Function Documentation

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( ScopedLock  )
private

Member Data Documentation

◆ _lock

Spinlock* _lock
private