Skip to content

Commit

Permalink
Update spinlock.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Mar 28, 2024
1 parent 1af9df9 commit 6d0a175
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utility/spinlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "utility.hpp"
#include <atomic>
#include <thread>
#include <tuple>

namespace gapp::detail
{
Expand All @@ -16,9 +16,12 @@ namespace gapp::detail
{
while (true)
{
if (!locked_.test_and_set(std::memory_order_relaxed))
{
std::ignore = locked_.test(std::memory_order_acquire);
break;
}
while (locked_.test(std::memory_order_relaxed)) GAPP_PAUSE();
if (!locked_.test_and_set(std::memory_order_acquire)) break;
std::this_thread::yield();
}
}

Expand Down

0 comments on commit 6d0a175

Please sign in to comment.