ifw-core 7.0.0
 
Loading...
Searching...
No Matches
ifw::core::utils::system::Mutex Class Reference

The Mutex class: Scope based mutex semaphore. The ifw::core::utils::system::Mutex semaphore is used to implement a safe mutex semaphore, at scope level. When entering the scope the semaphore is automatically created, based on a ID, if not existing, and locked. The semaphore created is recursive. When leaving the scope, the destructor will automatically unlock the semaphore. More...

#include <system.hpp>

Public Member Functions

 Mutex (const std::string &id)
 
 ~Mutex ()
 
const std::string & Id () const
 
void Lock ()
 
void Unlock ()
 

Static Public Member Functions

static void Clear ()
 Releases (deletes) all semaphores allocated. Use with caution!!
 

Detailed Description

The Mutex class: Scope based mutex semaphore. The ifw::core::utils::system::Mutex semaphore is used to implement a safe mutex semaphore, at scope level. When entering the scope the semaphore is automatically created, based on a ID, if not existing, and locked. The semaphore created is recursive. When leaving the scope, the destructor will automatically unlock the semaphore.

Example:

ifw::core::utils::system::Mutex tmp_mutex("MySemId"); { ... critical section ... }

Using the macros for this, makes critical sections in the code more conspicuous, i.e.:

BEGIN_CRIT_SEC("MySemId") { ... critical section ... } END_CRIT_SEC();

Constructor & Destructor Documentation

◆ Mutex()

ifw::core::utils::system::Mutex::Mutex ( const std::string & id)
explicit

◆ ~Mutex()

ifw::core::utils::system::Mutex::~Mutex ( )

Member Function Documentation

◆ Clear()

void ifw::core::utils::system::Mutex::Clear ( )
static

Releases (deletes) all semaphores allocated. Use with caution!!

◆ Id()

const std::string & ifw::core::utils::system::Mutex::Id ( ) const

◆ Lock()

void ifw::core::utils::system::Mutex::Lock ( )

◆ Unlock()

void ifw::core::utils::system::Mutex::Unlock ( )

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