sta-core/include/sta/mutex.hpp
2024-05-01 13:56:35 +02:00

49 lines
989 B
C++

/**
* @file
* @brief Mutex interface definition.
*/
#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
{
/**
* @brief Interface for mutex objects.
*
* @ingroup sta_core
*/
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(uint32_t timeout = STA_MUTEX_MAX_TIMEOUT) = 0;
/**
* @brief Release mutex.
*/
virtual void release() = 0;
static Mutex * ALWAYS_FREE; /**< Fake mutex that can always be acquired */
};
} // namespace sta
#endif // STA_CORE_MUTEX_HPP