1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00
Files
mariadb-columnstore-engine/utils/common/spinlock.h
2022-02-11 12:24:40 +00:00

27 lines
528 B
C++

#pragma once
#include <atomic>
namespace utils
{
inline void getSpinlock(std::atomic<bool>& lock)
{
bool _false = false;
while (!lock.compare_exchange_weak(_false, true, std::memory_order_acquire))
_false = false;
}
inline bool trySpinlock(std::atomic<bool>& lock)
{
bool _false = false;
bool ret = lock.compare_exchange_weak(_false, true, std::memory_order_acquire);
return ret;
}
inline void releaseSpinlock(std::atomic<bool>& lock)
{
lock.store(false, std::memory_order_release);
}
} // namespace utils