From be691582ee12613278af24cb5a824eeb357f6324 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 29 Jul 2024 11:27:22 -0400 Subject: some work on compositor --- euler/include/std/mutex.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 euler/include/std/mutex.hpp (limited to 'euler/include/std/mutex.hpp') 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 + +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); + } + + }; + +} -- cgit v1.2.3