From e7eedd234954509f4f5ec52b2d62cbc4a1723936 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 14 Jul 2025 15:39:09 +0000 Subject: libs: begin extraction of kernel std --- libs/kstd/src/mutex.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 libs/kstd/src/mutex.cpp (limited to 'libs/kstd/src/mutex.cpp') diff --git a/libs/kstd/src/mutex.cpp b/libs/kstd/src/mutex.cpp new file mode 100644 index 0000000..cfb1c84 --- /dev/null +++ b/libs/kstd/src/mutex.cpp @@ -0,0 +1,16 @@ +#include "kstd/mutex.hpp" + +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 -- cgit v1.2.3 From 833738f7023324172dbb0922fe1be9ad9cc88330 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 14 Jul 2025 20:35:38 +0000 Subject: libs: rename kstd headers to be more STL like --- libs/kstd/src/mutex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libs/kstd/src/mutex.cpp') diff --git a/libs/kstd/src/mutex.cpp b/libs/kstd/src/mutex.cpp index cfb1c84..137ebc0 100644 --- a/libs/kstd/src/mutex.cpp +++ b/libs/kstd/src/mutex.cpp @@ -1,4 +1,4 @@ -#include "kstd/mutex.hpp" +#include "kstd/mutex" namespace kstd { -- cgit v1.2.3 From b157e2c472d8bd67ac1656404a6a6ee821260f4b Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 29 Oct 2025 15:01:43 +0100 Subject: chore: reformat source code --- libs/kstd/src/mutex.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libs/kstd/src/mutex.cpp') diff --git a/libs/kstd/src/mutex.cpp b/libs/kstd/src/mutex.cpp index 137ebc0..da1357f 100644 --- a/libs/kstd/src/mutex.cpp +++ b/libs/kstd/src/mutex.cpp @@ -10,7 +10,13 @@ namespace kstd } } - auto mutex::try_lock() -> bool { return !locked.exchange(true, std::memory_order_acquire); } + auto mutex::try_lock() -> bool + { + return !locked.exchange(true, std::memory_order_acquire); + } - auto mutex::unlock() -> void { locked.store(false, std::memory_order_release); } + auto mutex::unlock() -> void + { + locked.store(false, std::memory_order_release); + } } // namespace kstd -- cgit v1.2.3 From 1945dd16716392e70e74efacd19e779f121bd1da Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Dec 2025 16:46:51 +0100 Subject: chore: fix missing includes --- libs/kstd/src/mutex.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libs/kstd/src/mutex.cpp') diff --git a/libs/kstd/src/mutex.cpp b/libs/kstd/src/mutex.cpp index da1357f..5a26154 100644 --- a/libs/kstd/src/mutex.cpp +++ b/libs/kstd/src/mutex.cpp @@ -1,5 +1,7 @@ #include "kstd/mutex" +#include + namespace kstd { auto mutex::lock() -> void -- cgit v1.2.3