Tier0: cleanup CThreadFastMutex

This commit is contained in:
Kawe Mazidjatari 2024-01-16 21:21:08 +01:00
parent 65cdc0c75b
commit 8ce0412405

View File

@ -13,25 +13,21 @@
int CThreadFastMutex::Lock(void) int CThreadFastMutex::Lock(void)
{ {
DWORD threadId = GetCurrentThreadId(); const DWORD threadId = GetCurrentThreadId();
LONG result = ThreadInterlockedCompareExchange((volatile LONG*)&m_lAddend, 0, 1); LONG result = ThreadInterlockedCompareExchange((volatile LONG*)&m_lAddend, 0, 1);
if (result) if (result)
{ {
if (m_nOwnerID == threadId) if (m_nOwnerID == threadId)
{ {
result = m_nDepth + 1; return ++m_nDepth;
m_nDepth = result;
return result;
} }
LONG cycle = 1; LONG cycle = 1;
LONG64 delay;
while (true) while (true)
{ {
delay = (10 * cycle); LONG64 delay = (10 * cycle);
if (delay) if (delay)
{ {
do do
@ -77,10 +73,7 @@ int CThreadFastMutex::Lock(void)
int CThreadFastMutex::Unlock() int CThreadFastMutex::Unlock()
{ {
LONG result; // eax LONG result = m_nDepth - 1;
HANDLE SemaphoreA; // rcx
result = m_nDepth - 1;
m_nDepth = result; m_nDepth = result;
if (!result) if (!result)
@ -92,12 +85,12 @@ int CThreadFastMutex::Unlock()
{ {
if (!m_hSemaphore) if (!m_hSemaphore)
{ {
SemaphoreA = CreateSemaphoreA(NULL, INIT_SEM_COUNT, MAX_SEM_COUNT, NULL); const HANDLE SemaphoreA = CreateSemaphoreA(NULL, INIT_SEM_COUNT, MAX_SEM_COUNT, NULL);
if (ThreadInterlockedAssignIf64( if (ThreadInterlockedAssignIf64((volatile LONG64*)&m_hSemaphore, NULL, (LONG64)SemaphoreA))
(volatile LONG64*)&m_hSemaphore, NULL, (LONG64)SemaphoreA))
CloseHandle(SemaphoreA); CloseHandle(SemaphoreA);
} }
return ReleaseSemaphore(m_hSemaphore, 1, NULL); return ReleaseSemaphore(m_hSemaphore, 1, NULL);
} }
} }