MIRA
Public Member Functions | Protected Attributes | List of all members
ScopedAccess< Protectee, Mutex > Class Template Reference

Grants thread-safe access to an object (the Protectee) that should be protected from concurrent access. More...

#include <thread/ScopedAccess.h>

Inheritance diagram for ScopedAccess< Protectee, Mutex >:
Inheritance graph
[legend]

Public Member Functions

 ScopedAccess (Protectee *p, Mutex *m, bool lockedAlready=false)
 This is used to create an access object to a protected object, which is passed as pointer. More...
 
 ~ScopedAccess ()
 
 ScopedAccess (ScopedAccess &&other) noexcept
 
ScopedAccessoperator= (ScopedAccess &&other) noexcept
 
Protectee * operator-> ()
 
const Protectee * operator-> () const
 
Protectee & operator* ()
 
const Protectee & operator* () const
 

Protected Attributes

Mutex * mMutex
 
Protectee * mObject
 

Detailed Description

template<typename Protectee, typename Mutex = void>
class mira::ScopedAccess< Protectee, Mutex >

Grants thread-safe access to an object (the Protectee) that should be protected from concurrent access.

The protectee or its owner can return a ScopedAccess object to the user. The ScopedAccess object contains a reference to the protectee and will delegate all calls to it. Moreover, the ScopedAccess will automatically take care of locking and unlocking, i.e. it will keep the mutex locked over its entire lifetime and release the lock when it goes out of scope.

A not specified Mutex type (default=void), will select the specialization for Mutex=void, where the Protectee itself is expected to provide lock/unlock.

Constructor & Destructor Documentation

◆ ScopedAccess() [1/2]

ScopedAccess ( Protectee *  p,
Mutex *  m,
bool  lockedAlready = false 
)
inline

This is used to create an access object to a protected object, which is passed as pointer.

The third parameter specifies if the object is already locked. If not (the default), it is locked immediately. Note that in both cases the object will be unlocked in ScopedAccess's destructor and should NOT be unlocked outside to prevent double unlock!

◆ ~ScopedAccess()

~ScopedAccess ( )
inline

◆ ScopedAccess() [2/2]

ScopedAccess ( ScopedAccess< Protectee, Mutex > &&  other)
inlinenoexcept

Member Function Documentation

◆ operator=()

ScopedAccess& operator= ( ScopedAccess< Protectee, Mutex > &&  other)
inlinenoexcept

◆ operator->() [1/2]

Protectee* operator-> ( )
inlineinherited

◆ operator->() [2/2]

const Protectee* operator-> ( ) const
inlineinherited

◆ operator*() [1/2]

Protectee& operator* ( )
inlineinherited

◆ operator*() [2/2]

const Protectee& operator* ( ) const
inlineinherited

Member Data Documentation

◆ mMutex

Mutex* mMutex
protected

◆ mObject

Protectee* mObject
protectedinherited

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