aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/shared/mutex.cpp
blob: 6598255afbf238c571a897e7dc482fde22fa42e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "arch/shared/mutex.hpp"

namespace teachos::arch::shared
{
  auto mutex::lock() -> void
  {
    while (!try_lock())
    {
      // Nothing to do
    }
  }

  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 teachos::arch::shared