blob: 0a27877929100e8c68fc17bb0a4cf0f5e0245e51 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}
};
}
|