olp-cpp-sdk  1.22.0
Public Types | Public Member Functions | Protected Attributes | List of all members
olp::thread::Atomic< Type, MutexType, ReadLockType > Class Template Reference

A simple atomic wrapper. More...

#include <Atomic.h>

Public Types

using value_type = Type
 Alias for the type.
 
using WriteLockType = std::lock_guard< MutexType >
 Alias for the atomic write mutex lock.
 

Public Member Functions

template<class SomeType >
 Atomic (SomeType &&am)
 Creates the Atomic instance. More...
 
 Atomic ()
 Creates the Atomic instance.
 
template<class Functor >
auto locked (Functor &&lambda) -> decltype(lambda(std::declval< Type & >()))
 Calls the lambda function using the unique lock. More...
 
template<class Functor >
auto locked (Functor &&lambda) const -> decltype(lambda(std::declval< const Type & >())) const
 Calls the lambda using the lock. More...
 
Type lockedCopy () const
 Gets a copy of the data using the lock. More...
 
Type lockedMove ()
 Gets a copy of the moved data using the unique lock. More...
 
template<class SomeType >
void lockedAssign (SomeType &&am)
 Assigns the data using the unique lock. More...
 
void lockedSwap (Type &other)
 Exchanges context with the Type object using the unique lock. More...
 
Type lockedSwapWithDefault ()
 Exchanges context with the Type object using the unique lock and moves data. More...
 
 operator bool () const
 Converts to bool if the wrapped type is bool convertible. More...
 

Protected Attributes

MutexType m_mutex
 Defines the lock type.
 
Type m
 The member type to which atomic access is required.
 

Detailed Description

template<class Type, typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
class olp::thread::Atomic< Type, MutexType, ReadLockType >

A simple atomic wrapper.

Depending on the provided MutexType, it can be multi-read/single-write or single-read/single-write.

Template Parameters
TypeThe member type to which atomic access is required.
MutexTypeDefines the lock type.
ReadLockTypeDefines the locking strategy for the atomic read operation.

Constructor & Destructor Documentation

◆ Atomic()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
template<class SomeType >
olp::thread::Atomic< Type, MutexType, ReadLockType >::Atomic ( SomeType &&  am)
inlineexplicit

Creates the Atomic instance.

Template Parameters
SomeTypeThe variable type that is used for initialization.
Parameters
amThe rvalue reference of the SomeType instance.

Member Function Documentation

◆ locked() [1/2]

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
template<class Functor >
auto olp::thread::Atomic< Type, MutexType, ReadLockType >::locked ( Functor &&  lambda) -> decltype(lambda(std::declval<Type&>()))
inline

Calls the lambda function using the unique lock.

Template Parameters
FunctorAccepts the single parameter of Type&.
Parameters
lambdaThe function of the Functor type.
Returns
The lambda result.

◆ locked() [2/2]

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
template<class Functor >
auto olp::thread::Atomic< Type, MutexType, ReadLockType >::locked ( Functor &&  lambda) const -> decltype(lambda(std::declval<const Type&>())) const
inline

Calls the lambda using the lock.

Used for the const version of this class.

Template Parameters
FunctorAccepts the single parameter of const Type&.
Parameters
lambdaThe function of the Functor type.
Returns
The lambda result.

◆ lockedAssign()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
template<class SomeType >
void olp::thread::Atomic< Type, MutexType, ReadLockType >::lockedAssign ( SomeType &&  am)
inline

Assigns the data using the unique lock.

Template Parameters
SomeTypeThe variable type that is used for initialization.
Parameters
amThe rvalue reference of the SomeType instance.

◆ lockedCopy()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
Type olp::thread::Atomic< Type, MutexType, ReadLockType >::lockedCopy ( ) const
inline

Gets a copy of the data using the lock.

Returns
The copy of the data.

◆ lockedMove()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
Type olp::thread::Atomic< Type, MutexType, ReadLockType >::lockedMove ( )
inline

Gets a copy of the moved data using the unique lock.

Returns
The copy of the moved data.

◆ lockedSwap()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
void olp::thread::Atomic< Type, MutexType, ReadLockType >::lockedSwap ( Type &  other)
inline

Exchanges context with the Type object using the unique lock.

Parameters
otherThe copy of the value specified in the Type object.

◆ lockedSwapWithDefault()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
Type olp::thread::Atomic< Type, MutexType, ReadLockType >::lockedSwapWithDefault ( )
inline

Exchanges context with the Type object using the unique lock and moves data.

Returns
The copy of the value specified in the Type object.

◆ operator bool()

template<class Type , typename MutexType = std::mutex, typename ReadLockType = std::lock_guard<MutexType>>
olp::thread::Atomic< Type, MutexType, ReadLockType >::operator bool ( ) const
inlineexplicit

Converts to bool if the wrapped type is bool convertible.

Returns
True if the wrapped type is bool convertible; false otherwise.

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