Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Burger::MutexLock Class Reference

Class for locking and releasing a mutex in a function. More...

Collaboration diagram for Burger::MutexLock:
Collaboration graph
[legend]

Public Member Functions

 MutexLock (Mutex *pMutex) noexcept
 Obtain a lock on a mutex.
 
 ~MutexLock ()
 Release a locked mutex.
 

Private Member Functions

 MutexLock (const MutexLock &)=delete
 
MutexLockoperator= (const MutexLock &)=delete
 
 MutexLock (MutexLock &&)=delete
 
MutexLockoperator= (MutexLock &&)=delete
 

Private Attributes

Mutexm_pMutex
 Pointer to the lock held.
 

Detailed Description

Class for locking and releasing a mutex in a function.


To ease the obtaining and releasing a lock on a Burger::Mutex, this class is passed a pointer to a mutex and obtains a lock immediately. When the function that has this class locally stored exits, the lock is released.

Note
This class is not to be used as a global variable or a member of another class. It will not release a lock until the class is destructed
// Statically created mutex
void foo(void)
{
// Obtain a lock on mutex
printf("Do stuff");
// Lock is released on function exit
}
Class for locking and releasing a mutex in a function.
Definition burger.h:6548
Class for creating a Mutex for a statically allocated critical section of data.
Definition burger.h:6514
Select a type based if the conditional is true or false.
Definition burger.h:3178
See also
MutexStatic and Mutex

Constructor & Destructor Documentation

◆ MutexLock() [1/3]

Burger::MutexLock::MutexLock ( const MutexLock & )
privatedelete

◆ MutexLock() [2/3]

Burger::MutexLock::MutexLock ( MutexLock && )
privatedelete

◆ MutexLock() [3/3]

Burger::MutexLock::MutexLock ( Mutex * pMutex)
inlinenoexcept

Obtain a lock on a mutex.


Locks the critical section upon construction. Will release it when the class is destroyed.

Note
nullptr pointers are NOT allowed!!
Parameters
pMutexPointer to a valid Mutex
See also
Mutex, MutexLock and ~MutexLock()

◆ ~MutexLock()

Burger::MutexLock::~MutexLock ( )
inline

Release a locked mutex.


Unlocks the critical section upon destruction.

See also
MutexLock and MutexLock(Mutex *)

Member Function Documentation

◆ operator=() [1/2]

MutexLock & Burger::MutexLock::operator= ( const MutexLock & )
privatedelete

◆ operator=() [2/2]

MutexLock & Burger::MutexLock::operator= ( MutexLock && )
privatedelete

Member Data Documentation

◆ m_pMutex

Mutex* Burger::MutexLock::m_pMutex
private

Pointer to the lock held.