#include "core/thread/Mutex.hpp" #include #include "core/utils/Meta.hpp" #include "core/utils/Utility.hpp" static void reset(mtx_t* m) { Core::memorySet(m, 0, sizeof(mtx_t)); } Core::Mutex::Mutex() : mutex() { CORE_ASSERT_ALIGNED_DATA(mutex, mtx_t); reset(mutex.as()); } static bool doesExist(mtx_t* t) { mtx_t zero{}; return !Core::memoryCompare(&zero, t, sizeof(mtx_t)); } Core::Mutex::~Mutex() { if(doesExist(mutex.as())) { mtx_destroy(mutex.as()); } } check_return Core::Error Core::Mutex::init() { if(doesExist(mutex.as())) { return Error::INVALID_STATE; } return mtx_init(mutex.as(), mtx_plain) != thrd_success ? Error::MUTEX_ERROR : Error::NONE; } check_return Core::Error Core::Mutex::lock() { return mtx_lock(mutex.as()) != thrd_success ? Error::MUTEX_ERROR : Error::NONE; } check_return Core::Error Core::Mutex::unlock() { return mtx_unlock(mutex.as()) != thrd_success ? Error::MUTEX_ERROR : Error::NONE; }