First commit.

This commit is contained in:
2023-12-17 03:29:08 -08:00
commit 09ced8e899
255 changed files with 45001 additions and 0 deletions

88
src/System/Mutex_W32.cpp Normal file
View File

@@ -0,0 +1,88 @@
#include "../../include/System/Mutex_W32.h"
#include "../../include/Str.h"
#include "../../include/Log.h"
namespace lwe
{
Mutex::~Mutex()
{
if (!initialized)
return;
if (!CloseHandle(hdl))
LWE_LOG_INT("Error", 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
}
Mutex::Mutex()
: hdl(nullptr)
{
}
Mutex::Mutex(const Mutex& mutex)
: BaseMutex(mutex), hdl(nullptr)
{
}
Mutex& Mutex::operator=(const Mutex& mutex)
{
if (this == &mutex)
return *this;
BaseMutex::operator=(mutex);
hdl = nullptr;
return *this;
}
void Mutex::Initialize()
{
if (initialized)
return;
hdl = CreateMutexW(nullptr, FALSE, nullptr);
if (!hdl)
{
LWE_LOG_INT("Error", 0, "Failed to create mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
return;
}
initialized = true;
}
void Mutex::UnInitialize()
{
if (!initialized)
return;
if (!CloseHandle(hdl))
LWE_LOG_INT("Error", 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
initialized = false;
}
void Mutex::Lock()
{
if (locked)
return;
if (WaitForSingleObject(hdl, LWE_INFINITE) == WAIT_FAILED)
{
LWE_LOG_INT("Error", 0, "Failed to lock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
return;
}
locked = true;
}
void Mutex::Unlock()
{
if (!locked)
return;
if (!ReleaseMutex(hdl))
LWE_LOG_INT("Error", 0, "Failed to unlock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
locked = false;
}
}