summaryrefslogtreecommitdiff
path: root/Runtime/Threading/Mutex.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-25 23:29:21 +0800
committerchai <chaifix@163.com>2021-10-25 23:29:21 +0800
commit7ecf913256fb396e3027aac3318d996a716a52ef (patch)
tree4540835c881a63b665e2a692bf30115fd29e8bb0 /Runtime/Threading/Mutex.h
parent0816cd70ca1a213b6ed872bcf3c0bf0912473722 (diff)
+ job system
Diffstat (limited to 'Runtime/Threading/Mutex.h')
-rw-r--r--Runtime/Threading/Mutex.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/Runtime/Threading/Mutex.h b/Runtime/Threading/Mutex.h
new file mode 100644
index 0000000..44f8cb9
--- /dev/null
+++ b/Runtime/Threading/Mutex.h
@@ -0,0 +1,39 @@
+#pragma once
+#include <windows.h>
+
+class Mutex
+{
+public:
+ Mutex();
+ ~Mutex();
+
+ void Lock();
+ void Unlock();
+
+private:
+ HANDLE m_Handle;
+
+};
+
+
+class MutexLocker
+{
+public:
+ MutexLocker(Mutex& mutex)
+ : m(mutex)
+ {
+ m.Lock();
+ };
+ ~MutexLocker()
+ {
+ m.Unlock();
+ }
+ operator bool() { return false; };
+private:
+ void* operator new(size_t);
+ Mutex& m;
+};
+
+#define _lock(m) \
+if(MutexLocker lock_##m = m){} else
+