summaryrefslogtreecommitdiff
path: root/euler/include/std/mutex.hpp
diff options
context:
space:
mode:
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);
+ }
+
+ };
+
+}