From 7ecf913256fb396e3027aac3318d996a716a52ef Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Oct 2021 23:29:21 +0800 Subject: + job system --- Runtime/Threading/Mutex.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Runtime/Threading/Mutex.h (limited to 'Runtime/Threading/Mutex.h') 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 + +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 + -- cgit v1.1-26-g67d0