This commit is contained in:
jeanlemotan
2024-07-02 18:13:47 +02:00
commit bbeaa887cd
173 changed files with 34365 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#include "spin_mutex.hpp"
#include "spin_wait.hpp"
namespace cppcoro
{
spin_mutex::spin_mutex() noexcept
: m_isLocked(false)
{
}
bool spin_mutex::try_lock() noexcept
{
return !m_isLocked.exchange(true, std::memory_order_acquire);
}
void spin_mutex::lock() noexcept
{
spin_wait wait;
while (!try_lock())
{
while (m_isLocked.load(std::memory_order_relaxed))
{
wait.spin_one();
}
}
}
void spin_mutex::unlock() noexcept
{
m_isLocked.store(false, std::memory_order_release);
}
}