summaryrefslogtreecommitdiff
path: root/euler/include/std/mutex.hpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-07-29 11:27:22 -0400
committerBenji Dial <benji@benjidial.net>2024-07-29 11:27:22 -0400
commitbe691582ee12613278af24cb5a824eeb357f6324 (patch)
tree5982ca3aad5257f515c93f62735ff3d630aa3ab3 /euler/include/std/mutex.hpp
parent3636fd21e079c47bd8d62e773e178f68fe9c2052 (diff)
downloadhilbert-os-be691582ee12613278af24cb5a824eeb357f6324.tar.gz
some work on compositor
Diffstat (limited to 'euler/include/std/mutex.hpp')
-rw-r--r--euler/include/std/mutex.hpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/euler/include/std/mutex.hpp b/euler/include/std/mutex.hpp
new file mode 100644
index 0000000..0a27877
--- /dev/null
+++ b/euler/include/std/mutex.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <euler/syscall.hpp>
+
+namespace std {
+
+ class mutex {
+
+ euler::syscall::stream_handle in_handle;
+ euler::syscall::stream_handle out_handle;
+
+ public:
+ inline mutex() noexcept {
+ euler::syscall::create_private_socket(in_handle, out_handle);
+ uint8_t byte = 0;
+ euler::syscall::write_to_stream(in_handle, 1, &byte);
+ }
+
+ mutex(const mutex &) = delete;
+
+ inline ~mutex() {
+ euler::syscall::close_stream(in_handle);
+ euler::syscall::close_stream(out_handle);
+ }
+
+ mutex &operator =(const mutex &) = delete;
+
+ inline void lock() {
+ uint8_t byte;
+ euler::syscall::read_from_stream(out_handle, 1, &byte);
+ }
+
+ inline void unlock() {
+ uint8_t byte = 0;
+ euler::syscall::write_to_stream(in_handle, 1, &byte);
+ }
+
+ };
+
+}