CsLibGuarded  1.4.2
libguarded::plain_guarded< T, M > Class Template Reference

#include <CsLibGuarded/cs_plain_guarded.h>

Public Member Functions

template<typename... Us>
 plain_guarded (Us &&... data)
 
handle lock ()
 
handle try_lock ()
 
template<class Duration>
handle try_lock_for (const Duration &duration)
 
template<class TimePoint>
handle try_lock_until (const TimePoint &timepoint)
 

Detailed Description

template<typename T, typename M = std::mutex>
class libguarded::plain_guarded< T, M >

This templated class wraps an object and allows only one thread at a time to access the protected object.

This class will use std::mutex for the internal locking mechanism by default. Other classes which are useful for the mutex type are std::recursive_mutex, std::timed_mutex, and std::recursive_timed_mutex.

The handle returned by the various lock methods is moveable but not copyable.

Definition at line 42 of file cs_plain_guarded.h.

Constructor & Destructor Documentation

template<typename T, typename M = std::mutex>
template<typename... Us>
libguarded::plain_guarded< T, M >::plain_guarded ( Us &&...   data)

Construct a guarded object. This constructor will accept any number of parameters, all of which are forwarded to the constructor of T.

Definition at line 58 of file cs_plain_guarded.h.

Member Function Documentation

template<typename T, typename M = std::mutex>
handle libguarded::plain_guarded< T, M >::lock ( )
nodiscard

Acquire a handle to the protected object. As a side effect, the protected object will be locked from access by any other thread. The lock will be automatically released when the handle is destroyed.

Definition at line 66 of file cs_plain_guarded.h.

template<typename T, typename M = std::mutex>
handle libguarded::plain_guarded< T, M >::try_lock ( )
nodiscard

Attempt to acquire a handle to the protected object. Returns a null handle if the object is already locked. As a side effect, the protected object will be locked from access by any other thread. The lock will be automatically released when the handle is destroyed.

Definition at line 76 of file cs_plain_guarded.h.

template<typename T, typename M = std::mutex>
template<class Duration>
handle libguarded::plain_guarded< T, M >::try_lock_for ( const Duration &  duration)
nodiscard

Attempt to acquire a handle to the protected object. As a side effect, the protected object will be locked from access by any other thread. The lock will be automatically released when the handle is destroyed.

Returns a null handle if the object is already locked, and does not become available for locking before the time duration has elapsed.

Calling this method requires that the underlying mutex type M supports the try_lock_for method. This is not true if M is the default std::mutex.

Definition at line 94 of file cs_plain_guarded.h.

template<typename T, typename M = std::mutex>
template<class TimePoint>
handle libguarded::plain_guarded< T, M >::try_lock_until ( const TimePoint &  timepoint)
nodiscard

Attempt to acquire a handle to the protected object. As a side effect, the protected object will be locked from access by any other thread. The lock will be automatically released when the handle is destroyed.

Returns a null handle if the object is already locked, and does not become available for locking before reaching the specified timepoint.

Calling this method requires that the underlying mutex type M supports the try_lock_until method. This is not true if M is the default std::mutex.

Definition at line 112 of file cs_plain_guarded.h.


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