mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-01 17:11:55 +00:00
Added mutex timeout and mutex ownership
This commit is contained in:
parent
240787557d
commit
2996e9a70b
@ -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.
|
||||
*/
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user