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.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Runtime/Threading/Mutex.cpp (limited to 'Runtime/Threading/Mutex.cpp') diff --git a/Runtime/Threading/Mutex.cpp b/Runtime/Threading/Mutex.cpp new file mode 100644 index 0000000..eabe48d --- /dev/null +++ b/Runtime/Threading/Mutex.cpp @@ -0,0 +1,25 @@ +#include "Thread.h" +#include "Mutex.h" + +Mutex::Mutex() +{ + m_Handle = ::CreateMutex(NULL, FALSE, NULL); + if (!m_Handle) + throw ThreadException("Cant use win32 mutex."); +} + +Mutex::~Mutex() +{ + ::CloseHandle(m_Handle); + m_Handle = NULL; +} + +void Mutex::Lock() +{ + ::WaitForSingleObject(m_Handle, (~(uint32)0)); +} + +void Mutex::Unlock() +{ + ::ReleaseMutex(m_Handle); +} \ No newline at end of file -- cgit v1.1-26-g67d0