nlib
nn::nlib::threading::CriticalSection Class Reference

Reentrant mutex. More...

#include "nn/nlib/threading/CriticalSection.h"

Public Types

typedef nlib_mutexnative_handle_type
 typedef to a pointer type to a native mutex.
 

Public Member Functions

constexpr CriticalSection () noexcept=default
 Instantiates the object with default parameters (default constructor).
 
void lock () noexcept NLIB_ACQUIRE()
 Gets a lock, and enters the critical section. Blocks until it can get a lock.
 
void unlock () noexcept NLIB_RELEASE()
 Releases the lock, and exits the critical section.
 
NLIB_CHECK_RESULT bool try_lock () noexcept NLIB_TRY_ACQUIRE(true)
 Gets a lock, and attempts to enter the critical section. More...
 
native_handle_type native_handle () noexcept NLIB_RETURN_CAPABILITY(mutex_)
 Gets a pointer to a native type mutex. More...
 

Detailed Description

Reentrant mutex.

Description
Corresponds tostd::recursive_mutex in C++11.
Use with lock and unlock as shown in the example below.
c.lock();
// .... Process that requires exclusion.
c.unlock();
Alternatively, use ScopedLock as shown below.
{
ScopedLock<CriticalSection> l; // Locked by the constructor.
// .... Process that requires exclusion.
// unlock by destructor when leaving scope.
}

Definition at line 73 of file CriticalSection.h.

Member Function Documentation

◆ native_handle()

nn::nlib::threading::CriticalSection::native_handle ( )
inlinenoexcept

Gets a pointer to a native type mutex.

Returns
The pointer to the mutex.

Definition at line 102 of file CriticalSection.h.

◆ try_lock()

nn::nlib::threading::CriticalSection::try_lock ( )
inlinenoexcept

Gets a lock, and attempts to enter the critical section.

Returns
Returns true if a lock is acquired.

Definition at line 95 of file CriticalSection.h.


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