aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/src/mutex.cpp
blob: 137ebc0f143618ce0e24a25a438d377f6a8f4aab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "kstd/mutex"

namespace kstd
{
  auto mutex::lock() -> void
  {
    while (!try_lock())
    {
      asm volatile("nop");
    }
  }

  auto mutex::try_lock() -> bool { return !locked.exchange(true, std::memory_order_acquire); }

  auto mutex::unlock() -> void { locked.store(false, std::memory_order_release); }
}  // namespace kstd