mirror of
https://github.com/Icinga/icinga2.git
synced 2026-04-10 03:16:29 -04:00
23 lines
373 B
C++
23 lines
373 B
C++
|
|
/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */
|
||
|
|
|
||
|
|
#include "base/spinlock.hpp"
|
||
|
|
#include <atomic>
|
||
|
|
|
||
|
|
using namespace icinga;
|
||
|
|
|
||
|
|
void SpinLock::lock()
|
||
|
|
{
|
||
|
|
while (m_Locked.test_and_set(std::memory_order_acquire)) {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool SpinLock::try_lock()
|
||
|
|
{
|
||
|
|
return !m_Locked.test_and_set(std::memory_order_acquire);
|
||
|
|
}
|
||
|
|
|
||
|
|
void SpinLock::unlock()
|
||
|
|
{
|
||
|
|
m_Locked.clear(std::memory_order_release);
|
||
|
|
}
|