summaryrefslogtreecommitdiff
path: root/Client/Source/Threading/Mutex.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-13 00:07:19 +0800
committerchai <chaifix@163.com>2021-12-13 00:07:19 +0800
commit60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 (patch)
treeb2c7b0a868f18159dbc43d8954e1bd7668549a88 /Client/Source/Threading/Mutex.h
+init
Diffstat (limited to 'Client/Source/Threading/Mutex.h')
-rw-r--r--Client/Source/Threading/Mutex.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/Client/Source/Threading/Mutex.h b/Client/Source/Threading/Mutex.h
new file mode 100644
index 0000000..eed69aa
--- /dev/null
+++ b/Client/Source/Threading/Mutex.h
@@ -0,0 +1,39 @@
+#pragma once
+#include <windows.h>
+
+class Mutex
+{
+public:
+ Mutex();
+ ~Mutex();
+
+ void LockSelf();
+ void UnlockSelf();
+
+private:
+ HANDLE m_Handle;
+
+};
+
+
+class MutexLocker
+{
+public:
+ MutexLocker(Mutex& mutex)
+ : m(mutex)
+ {
+ m.LockSelf();
+ };
+ ~MutexLocker()
+ {
+ m.UnlockSelf();
+ }
+ operator bool() { return false; };
+private:
+ void* operator new(size_t);
+ Mutex& m;
+};
+
+#define Lock(m) \
+if(MutexLocker lock_##m = m){} else
+