Skip to content

Instantly share code, notes, and snippets.

@namkazt
Created August 16, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namkazt/9a09b8f51bd5fc95fdf75284690f7795 to your computer and use it in GitHub Desktop.
Save namkazt/9a09b8f51bd5fc95fdf75284690f7795 to your computer and use it in GitHub Desktop.
mutex concept
Mutex::Mutex()
{
g_isLocked = false;
svcCreateMutex(&g_mutexHandle, g_isLocked);
}
Mutex::~Mutex()
{
svcReleaseMutex(g_mutexHandle);
}
void Mutex::Lock()
{
if(g_isLocked)
{
svcWaitSynchronization(g_mutexHandle, U64_MAX);
}else
{
g_isLocked = true;
}
}
void Mutex::Unlock()
{
if (g_isLocked)
{
svcSignalEvent(g_mutexHandle);
g_isLocked = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment