diff options
Diffstat (limited to 'libs/kstd/src/mutex.cpp')
| -rw-r--r-- | libs/kstd/src/mutex.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libs/kstd/src/mutex.cpp b/libs/kstd/src/mutex.cpp new file mode 100644 index 0000000..5a26154 --- /dev/null +++ b/libs/kstd/src/mutex.cpp @@ -0,0 +1,24 @@ +#include "kstd/mutex" + +#include <atomic> + +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 |
