summaryrefslogtreecommitdiff
path: root/euler/include/std/unique_lock.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/unique_lock.hpp
parent3636fd21e079c47bd8d62e773e178f68fe9c2052 (diff)
downloadhilbert-os-be691582ee12613278af24cb5a824eeb357f6324.tar.gz
some work on compositor
Diffstat (limited to 'euler/include/std/unique_lock.hpp')
-rw-r--r--euler/include/std/unique_lock.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/euler/include/std/unique_lock.hpp b/euler/include/std/unique_lock.hpp
new file mode 100644
index 0000000..14b3645
--- /dev/null
+++ b/euler/include/std/unique_lock.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+namespace std {
+
+ template <class Mutex>
+ class unique_lock {
+
+ Mutex *the_mutex;
+ bool has_locked;
+
+ public:
+ inline unique_lock() noexcept : the_mutex(0) {}
+
+ unique_lock(const unique_lock &other) = delete;
+
+ inline unique_lock(unique_lock &&other) noexcept
+ : the_mutex(other.the_mutex), has_locked(other.has_locked) {
+ other.the_mutex = 0;
+ }
+
+ inline explicit unique_lock(Mutex &m)
+ : the_mutex(&m), has_locked(true) {
+ the_mutex->lock();
+ }
+
+ inline ~unique_lock() {
+ if (the_mutex && has_locked)
+ the_mutex->unlock();
+ }
+
+ unique_lock &operator =(const unique_lock &other) = delete;
+
+ inline unique_lock &operator =(unique_lock &&other) {
+ if (the_mutex && has_locked)
+ the_mutex->unlock();
+ the_mutex = other.the_mutex;
+ has_locked = other.has_locked;
+ other.the_mutex = 0;
+ }
+
+ inline void lock() {
+ the_mutex->lock();
+ has_locked = true;
+ }
+
+ inline void unlock() {
+ the_mutex->unlock();
+ has_locked = false;
+ }
+
+ };
+
+}