mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-28 21:17:33 +00:00
Added mutex timeout and mutex ownership
This commit is contained in:
@@ -5,6 +5,13 @@
|
|||||||
#ifndef STA_CORE_MUTEX_HPP
|
#ifndef STA_CORE_MUTEX_HPP
|
||||||
#define 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
|
namespace sta
|
||||||
{
|
{
|
||||||
@@ -16,10 +23,18 @@ namespace sta
|
|||||||
class Mutex
|
class Mutex
|
||||||
{
|
{
|
||||||
public:
|
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.
|
* @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.
|
* @brief Release mutex.
|
||||||
*/
|
*/
|
||||||
|
@@ -9,12 +9,16 @@ namespace sta
|
|||||||
class DummyMutex : public Mutex
|
class DummyMutex : public Mutex
|
||||||
{
|
{
|
||||||
public:
|
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 {}
|
void release() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
static DummyMutex dummyMutex;
|
static DummyMutex dummyMutex;
|
||||||
|
|
||||||
|
|
||||||
Mutex * Mutex::ALWAYS_FREE = &dummyMutex;
|
Mutex * Mutex::ALWAYS_FREE = &dummyMutex;
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
Reference in New Issue
Block a user