EHS/src/system/Mutex_PT.cpp
Karutoh bcd71cf2b5
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s
Adjusted workflow.
2024-02-05 22:25:30 -08:00

76 lines
1014 B
C++

#include "ehs/system/Mutex_PT.h"
namespace ehs
{
Mutex::~Mutex()
{
if (!initialized)
return;
pthread_mutex_destroy(&hdl);
}
Mutex::Mutex()
: hdl{}
{
}
Mutex::Mutex(const Mutex& mutex)
: BaseMutex(mutex), hdl{}
{
}
Mutex& Mutex::operator=(const Mutex& mutex)
{
if (this == &mutex)
return *this;
BaseMutex::operator=(mutex);
hdl = {};
return *this;
}
void Mutex::Initialize()
{
if (initialized)
return;
pthread_mutex_t hdl = {};
int code = pthread_mutex_init(&hdl, nullptr);
initialized = true;
}
void Mutex::UnInitialize()
{
if (!initialized)
return;
pthread_mutex_destroy(&hdl);
initialized = false;
}
void Mutex::Lock()
{
if (locked)
return;
pthread_mutex_lock(&hdl);
locked = true;
}
void Mutex::Unlock()
{
if (!locked)
return;
pthread_mutex_unlock(&hdl);
locked = false;
}
}