nlib
nn::nlib::threading::UniqueLock< T > Class Template Reference

Class to wrap objects like CriticalSection. More...

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

Public Types

typedef T mutex_type
 T.
 
typedef mutex_type::native_handle_type native_handle_type
 mutex_type::native_handle_type.
 

Public Member Functions

void lock () NLIB_ACQUIRE()
 Locks the associated CriticalSection or other object.
 
void unlock () noexcept NLIB_RELEASE()
 Unlocks the associated CriticalSection or other object.
 
NLIB_CHECK_RESULT bool try_lock () noexcept NLIB_TRY_ACQUIRE(true)
 Attempts to lock the associated object like CriticalSection.
 
NLIB_CHECK_RESULT bool try_lock_for (const TimeSpan &timeout) noexcept NLIB_TRY_ACQUIRE(true)
 Attempts to lock with timeout the associated CriticalSection or other object.
 
NLIB_CHECK_RESULT bool try_lock_until (const DateTime &abstime) noexcept NLIB_TRY_ACQUIRE(true)
 Attempts to lock with timeout the associated CriticalSection or other object.
 
void swap (UniqueLock &rhs) noexcept
 Attempts to swap the associated CriticalSection or other object. More...
 
mutex_typerelease () noexcept NLIB_RETURN_CAPABILITY(*locker_)
 Removes the association. Does not unlock. More...
 
mutex_typemutex () const noexcept NLIB_RETURN_CAPABILITY(*locker_)
 Gets the pointer to the associated object like CriticalSection. More...
 
native_handle_type native_handle () NLIB_RETURN_CAPABILITY(*locker_)
 Returns an implementation-specific handle representing a lock.
 
bool owns_lock () const noexcept
 Returns true if the lock associated with UniqueLock is locked.
 
 operator bool () const
 Returns true if the lock is held.
 
Basic Member Functions
 UniqueLock () noexcept
 Initializes an object without creating an association.
 
 UniqueLock (mutex_type &rhs) NLIB_ACQUIRE(locker_)
 Locks the object like CriticalSection and associates it with this object. More...
 
 UniqueLock (mutex_type &rhs, AdoptLockType) NLIB_REQUIRES(locker_)
 Assumes an object like CriticalSection is already locked, and initializes the object without locking it. Unlocked in the destructor. More...
 
 UniqueLock (mutex_type &rhs, DeferLockType) noexcept NLIB_EXCLUDES(locker_)
 Initializes an object without locking. More...
 
 UniqueLock (mutex_type &rhs, TryToLockType)
 Attempts to lock using try_lock when initializing. More...
 
UniqueLockassign (UniqueLock &rhs, move_tag)
 Assigns the object by using swap for a move.
 
 UniqueLock (UniqueLock &rhs, move_tag)
 Instantiates the object by using swap for a move.
 
 UniqueLock (UniqueLock &&rhs)
 Instantiates the object (move constructor). This function is useful when using C++11.
 
UniqueLockoperator= (UniqueLock &&rhs)
 Move assignment operator. This function is useful when using C++11.
 

Detailed Description

template<class T>
class nn::nlib::threading::UniqueLock< T >

Class to wrap objects like CriticalSection.

Template Parameters
TClasses such as CriticalSection.

Definition at line 308 of file CriticalSection.h.

Constructor & Destructor Documentation

◆ UniqueLock() [1/4]

template<class T >
nn::nlib::threading::UniqueLock< T >::UniqueLock ( mutex_type rhs)
inlineexplicit

Locks the object like CriticalSection and associates it with this object.

Parameters
[in]rhsObjects such as CriticalSection.

Definition at line 313 of file CriticalSection.h.

◆ UniqueLock() [2/4]

template<class T >
nn::nlib::threading::UniqueLock< T >::UniqueLock ( mutex_type rhs,
AdoptLockType   
)
inline

Assumes an object like CriticalSection is already locked, and initializes the object without locking it. Unlocked in the destructor.

Parameters
[in]rhsObjects such as CriticalSection.

Definition at line 317 of file CriticalSection.h.

◆ UniqueLock() [3/4]

template<class T >
nn::nlib::threading::UniqueLock< T >::UniqueLock ( mutex_type rhs,
DeferLockType   
)
inlinenoexcept

Initializes an object without locking.

Parameters
[in]rhsObjects such as CriticalSection.

Definition at line 319 of file CriticalSection.h.

◆ UniqueLock() [4/4]

template<class T >
nn::nlib::threading::UniqueLock< T >::UniqueLock ( mutex_type rhs,
TryToLockType   
)
inline

Attempts to lock using try_lock when initializing.

Parameters
[in]rhsObjects such as CriticalSection.

Definition at line 322 of file CriticalSection.h.

Member Function Documentation

◆ mutex()

template<class T >
nn::nlib::threading::UniqueLock< T >::mutex ( ) const
inlinenoexcept

Gets the pointer to the associated object like CriticalSection.

Returns
Pointer to the object associated, such as CriticalSection.

Definition at line 383 of file CriticalSection.h.

◆ release()

template<class T >
nn::nlib::threading::UniqueLock< T >::release ( )
inlinenoexcept

Removes the association. Does not unlock.

Returns
Pointer to the object associated, such as CriticalSection.

Definition at line 377 of file CriticalSection.h.

◆ swap()

template<class T >
nn::nlib::threading::UniqueLock< T >::swap ( UniqueLock< T > &  rhs)
inlinenoexcept

Attempts to swap the associated CriticalSection or other object.

Parameters
[in]rhsObject to swap.

Definition at line 372 of file CriticalSection.h.


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