mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
45 lines
784 B
C++
45 lines
784 B
C++
/**
|
|
* @file
|
|
* @brief Atomic mutex implementation.
|
|
*
|
|
* Configuration:
|
|
* STA_STDLIB_HAS_ATOMIC: Enable module
|
|
*/
|
|
#ifndef STA_CORE_ATOMIC_MUTEX_HPP
|
|
#define STA_CORE_ATOMIC_MUTEX_HPP
|
|
|
|
#include <sta/config.hpp>
|
|
#ifdef STA_STDLIB_HAS_ATOMIC
|
|
# define STA_ATOMIC_ENABLED
|
|
#endif // STA_STDLIB_HAS_ATOMIC
|
|
|
|
#if defined(STA_ATOMIC_ENABLED) || defined(DOXYGEN)
|
|
|
|
#include <sta/mutex.hpp>
|
|
|
|
#include <atomic>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief Implementation of `Mutex` interface using `std::atomic_flag`.
|
|
*/
|
|
class AtomicMutex : public Mutex
|
|
{
|
|
public:
|
|
AtomicMutex();
|
|
|
|
void acquire() override;
|
|
void release() override;
|
|
|
|
private:
|
|
std::atomic_flag lock_; /**< Atomic flag used as lock */
|
|
};
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_ATOMIC_ENABLED
|
|
|
|
#endif // STA_CORE_ATOMIC_MUTEX_HPP
|