MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/logging/SpinlockMutex.hh
2024-06-07 11:12:56 +03:00

43 lines
581 B
C++

/*
* Spinlock_mutex.hh
*
* Created on: 22 пїЅпїЅпїЅ. 2020 пїЅ.
* Author: _aam
*/
#pragma once
#include <atomic>
namespace logging {
class SpinlockMutex {
std::atomic_flag spinlock_flag;
unsigned long tick_tok;
public:
SpinlockMutex() : tick_tok(0) { spinlock_flag.clear(); };
~SpinlockMutex() {
unlock();
}
void lock() {
while( spinlock_flag.test_and_set(std::memory_order_acquire) )
tick_tok++;
}
void unlock() {
spinlock_flag.clear(std::memory_order_release);
};
};
}