2408f7dc37
Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
79 lines
2.2 KiB
C
79 lines
2.2 KiB
C
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <AzCore/PlatformIncl.h>
|
|
#include <AzCore/std/parallel/semaphore.h> // for CreateSemaphore
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// CryLock_WinMutex
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CryLock_WinMutex::CryLock_WinMutex()
|
|
: m_hdl(CreateMutex(NULL, FALSE, NULL)) {}
|
|
CryLock_WinMutex::~CryLock_WinMutex()
|
|
{
|
|
CloseHandle(m_hdl);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void CryLock_WinMutex::Lock()
|
|
{
|
|
WaitForSingleObject(m_hdl, INFINITE);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void CryLock_WinMutex::Unlock()
|
|
{
|
|
ReleaseMutex(m_hdl);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CryLock_WinMutex::TryLock()
|
|
{
|
|
return WaitForSingleObject(m_hdl, 0) != WAIT_TIMEOUT;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// CryLock_CritSection
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CryLock_CritSection::CryLock_CritSection()
|
|
{
|
|
InitializeCriticalSection((CRITICAL_SECTION*)&m_cs);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
CryLock_CritSection::~CryLock_CritSection()
|
|
{
|
|
DeleteCriticalSection((CRITICAL_SECTION*)&m_cs);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void CryLock_CritSection::Lock()
|
|
{
|
|
EnterCriticalSection((CRITICAL_SECTION*)&m_cs);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void CryLock_CritSection::Unlock()
|
|
{
|
|
LeaveCriticalSection((CRITICAL_SECTION*)&m_cs);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
bool CryLock_CritSection::TryLock()
|
|
{
|
|
return TryEnterCriticalSection((CRITICAL_SECTION*)&m_cs) != FALSE;
|
|
}
|