Added mutex timeout and mutex ownership

This commit is contained in:
dario 2024-05-01 13:56:35 +02:00
parent 240787557d
commit 2996e9a70b
2 changed files with 22 additions and 3 deletions

View File

@ -5,6 +5,13 @@
#ifndef STA_CORE_MUTEX_HPP
#define STA_CORE_MUTEX_HPP
#include <cstdint>
/**
* @brief Maximum timeout for a mutex.
*
*/
#define STA_MUTEX_MAX_TIMEOUT 0xFFFFFFFFU
namespace sta
{
@ -16,10 +23,18 @@ namespace sta
class Mutex
{
public:
/**
* @brief Method for checking mutex ownership.
*
* @return Returns true if the currently running thread is the owner of the mutex.
*/
virtual bool isCurrentThreadOwner() = 0;
/**
* @brief Block until mutex has been acquired.
*/
virtual void acquire() = 0;
virtual void acquire(uint32_t timeout = STA_MUTEX_MAX_TIMEOUT) = 0;
/**
* @brief Release mutex.
*/

View File

@ -9,12 +9,16 @@ namespace sta
class DummyMutex : public Mutex
{
public:
void acquire() override {}
bool isCurrentThreadOwner()
{
return true; // Your mutex? It's OUR mutex, comrade!
};
void acquire(uint32_t timeout /* = STA_MUTEX_MAX_TIMEOUT */) override {}
void release() override {}
};
static DummyMutex dummyMutex;
Mutex * Mutex::ALWAYS_FREE = &dummyMutex;
} // namespace sta