Add mutex interface

This commit is contained in:
Henrik Stickann 2022-04-09 21:21:21 +02:00
commit 2e9f64a045
2 changed files with 47 additions and 0 deletions

27
include/sta/mutex.hpp Normal file
View File

@ -0,0 +1,27 @@
#ifndef STA_MUTEX_HPP
#define STA_MUTEX_HPP
namespace sta
{
/**
* @brief Interface for mutex objects.
*/
class Mutex
{
public:
/**
* @brief Block until mutex has been acquired
*/
virtual void acquire() = 0;
/**
* @brief Release mutex
*/
virtual void release() = 0;
static Mutex * ALWAYS_FREE; /**< Fake mutex that can always be acquired */
};
} // namespace sta
#endif // STA_MUTEX_HPP

20
src/mutex.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <sta/mutex.hpp>
namespace sta
{
/**
* @brief Dummy mutex implementation with no access control.
*/
class DummyMutex : public Mutex
{
public:
void acquire() override {}
void release() override {}
};
static DummyMutex dummyMutex;
Mutex * Mutex::ALWAYS_FREE = &dummyMutex;
} // namespace sta