#include "arch/shared/mutex.hpp" namespace teachos::arch::shared { auto mutex::lock() -> void { while (true) { if (!locked.exchange(true, std::memory_order_acquire)) { return; } } } /** * @brief Try to lock the mutex (non-blocking) * * @return true if lock has been acquired and false otherwise */ auto mutex::try_lock() -> bool { return !locked.exchange(true, std::memory_order_acquire); } /** * @brief Unlock the mutex */ auto mutex::unlock() -> void { locked.store(false, std::memory_order_release); } } // namespace teachos::arch::shared