mirror of
https://github.com/reactos/reactos.git
synced 2026-07-07 07:40:24 +08:00
- Use compiler intrinsics instead of hidden dependency of intrlck
svn path=/trunk/; revision=25672
This commit is contained in:
@@ -59,13 +59,13 @@ RtlpCreateCriticalSectionSem(PRTL_CRITICAL_SECTION CriticalSection)
|
||||
|
||||
/* We failed, this is bad... */
|
||||
DPRINT1("Failed to Create Event!\n");
|
||||
InterlockedDecrement(&CriticalSection->LockCount);
|
||||
_InterlockedDecrement(&CriticalSection->LockCount);
|
||||
RtlRaiseStatus(Status);
|
||||
return;
|
||||
}
|
||||
DPRINT("Created Event: %p \n", hNewEvent);
|
||||
|
||||
if ((hEvent = InterlockedCompareExchangePointer((PVOID*)&CriticalSection->LockSemaphore,
|
||||
if ((hEvent = _InterlockedCompareExchangePointer((PVOID*)&CriticalSection->LockSemaphore,
|
||||
(PVOID)hNewEvent,
|
||||
0))) {
|
||||
|
||||
@@ -427,7 +427,7 @@ RtlEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||
HANDLE Thread = (HANDLE)NtCurrentTeb()->Cid.UniqueThread;
|
||||
|
||||
/* Try to Lock it */
|
||||
if (InterlockedIncrement(&CriticalSection->LockCount) != 0) {
|
||||
if (_InterlockedIncrement(&CriticalSection->LockCount) != 0) {
|
||||
|
||||
/*
|
||||
* We've failed to lock it! Does this thread
|
||||
@@ -611,7 +611,7 @@ RtlLeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||
if (--CriticalSection->RecursionCount) {
|
||||
|
||||
/* Someone still owns us, but we are free. This needs to be done atomically. */
|
||||
InterlockedDecrement(&CriticalSection->LockCount);
|
||||
_InterlockedDecrement(&CriticalSection->LockCount);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -620,7 +620,7 @@ RtlLeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||
CriticalSection->OwningThread = 0;
|
||||
|
||||
/* Was someone wanting us? This needs to be done atomically. */
|
||||
if (-1 != InterlockedDecrement(&CriticalSection->LockCount)) {
|
||||
if (-1 != _InterlockedDecrement(&CriticalSection->LockCount)) {
|
||||
|
||||
/* Let him have us */
|
||||
RtlpUnWaitCriticalSection(CriticalSection);
|
||||
@@ -652,9 +652,9 @@ NTAPI
|
||||
RtlTryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||
{
|
||||
/* Try to take control */
|
||||
if (InterlockedCompareExchange(&CriticalSection->LockCount,
|
||||
0,
|
||||
-1) == -1) {
|
||||
if (_InterlockedCompareExchange(&CriticalSection->LockCount,
|
||||
0,
|
||||
-1) == -1) {
|
||||
|
||||
/* It's ours */
|
||||
CriticalSection->OwningThread = NtCurrentTeb()->Cid.UniqueThread;
|
||||
@@ -664,7 +664,7 @@ RtlTryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
|
||||
} else if (CriticalSection->OwningThread == NtCurrentTeb()->Cid.UniqueThread) {
|
||||
|
||||
/* It's already ours */
|
||||
InterlockedIncrement(&CriticalSection->LockCount);
|
||||
_InterlockedIncrement(&CriticalSection->LockCount);
|
||||
CriticalSection->RecursionCount++;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "rtlp.h"
|
||||
|
||||
#include <pseh/pseh.h>
|
||||
#include <intrin.h>
|
||||
|
||||
#endif /* RTL_H */
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ InterlockedAnd(IN OUT volatile LONG *Target,
|
||||
j = *Target;
|
||||
do {
|
||||
i = j;
|
||||
j = InterlockedCompareExchange((PLONG)Target,
|
||||
i & Set,
|
||||
i);
|
||||
j = _InterlockedCompareExchange((PLONG)Target,
|
||||
i & Set,
|
||||
i);
|
||||
|
||||
} while (i != j);
|
||||
|
||||
@@ -52,9 +52,9 @@ InterlockedOr(IN OUT volatile LONG *Target,
|
||||
j = *Target;
|
||||
do {
|
||||
i = j;
|
||||
j = InterlockedCompareExchange((PLONG)Target,
|
||||
i | Set,
|
||||
i);
|
||||
j = _InterlockedCompareExchange((PLONG)Target,
|
||||
i | Set,
|
||||
i);
|
||||
|
||||
} while (i != j);
|
||||
|
||||
@@ -173,8 +173,8 @@ RtlpReleaseWaitBlockLockExclusive(IN OUT PRTL_SRWLOCK SRWLock,
|
||||
}
|
||||
}
|
||||
|
||||
(void)InterlockedExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue);
|
||||
(void)_InterlockedExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue);
|
||||
|
||||
if (FirstWaitBlock->Exclusive)
|
||||
{
|
||||
@@ -229,8 +229,8 @@ RtlpReleaseWaitBlockLockLastShared(IN OUT PRTL_SRWLOCK SRWLock,
|
||||
NewValue = RTL_SRWLOCK_OWNED;
|
||||
}
|
||||
|
||||
(void)InterlockedExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue);
|
||||
(void)_InterlockedExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue);
|
||||
|
||||
(void)InterlockedOr(&FirstWaitBlock->Wake,
|
||||
TRUE);
|
||||
@@ -464,9 +464,9 @@ RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock)
|
||||
NewValue = (CurrentValue >> RTL_SRWLOCK_BITS) + 1;
|
||||
NewValue = (NewValue << RTL_SRWLOCK_BITS) | (CurrentValue & RTL_SRWLOCK_MASK);
|
||||
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
/* Successfully incremented the shared count, we acquired the lock */
|
||||
break;
|
||||
@@ -543,9 +543,9 @@ RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock)
|
||||
ASSERT_SRW_WAITBLOCK(&StackWaitBlock);
|
||||
|
||||
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED;
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
RtlpAcquireSRWLockSharedWait(SRWLock,
|
||||
&StackWaitBlock,
|
||||
@@ -565,9 +565,9 @@ RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock)
|
||||
RTL_SRWLOCK_SHARED nor the RTL_SRWLOCK_OWNED bit is set */
|
||||
ASSERT(!(CurrentValue & RTL_SRWLOCK_CONTENDED));
|
||||
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
/* Successfully set the shared count, we acquired the lock */
|
||||
break;
|
||||
@@ -624,9 +624,9 @@ RtlReleaseSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock)
|
||||
NewValue = (NewValue << RTL_SRWLOCK_BITS) | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_OWNED;
|
||||
}
|
||||
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
/* Successfully released the lock */
|
||||
break;
|
||||
@@ -683,9 +683,9 @@ RtlAcquireSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock)
|
||||
|
||||
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_CONTENDED | RTL_SRWLOCK_OWNED;
|
||||
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
RtlpAcquireSRWLockExclusiveWait(SRWLock,
|
||||
&StackWaitBlock);
|
||||
@@ -741,9 +741,9 @@ AddWaitBlock:
|
||||
ASSERT_SRW_WAITBLOCK(&StackWaitBlock);
|
||||
|
||||
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED;
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
RtlpAcquireSRWLockExclusiveWait(SRWLock,
|
||||
&StackWaitBlock);
|
||||
@@ -811,9 +811,9 @@ RtlReleaseSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock)
|
||||
ASSERT(!(CurrentValue & ~RTL_SRWLOCK_OWNED));
|
||||
|
||||
NewValue = 0;
|
||||
if (InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
if (_InterlockedCompareExchangePointer(&SRWLock->Ptr,
|
||||
(PVOID)NewValue,
|
||||
(PVOID)CurrentValue) == (PVOID)CurrentValue)
|
||||
{
|
||||
/* We released the lock */
|
||||
break;
|
||||
|
||||
@@ -55,9 +55,9 @@ RtlpInitializeThreadPool(VOID)
|
||||
|
||||
do
|
||||
{
|
||||
InitStatus = InterlockedCompareExchange(&ThreadPoolInitialized,
|
||||
2,
|
||||
0);
|
||||
InitStatus = _InterlockedCompareExchange(&ThreadPoolInitialized,
|
||||
2,
|
||||
0);
|
||||
if (InitStatus == 0)
|
||||
{
|
||||
/* We're the first thread to initialize the thread pool */
|
||||
@@ -91,8 +91,8 @@ RtlpInitializeThreadPool(VOID)
|
||||
|
||||
Finish:
|
||||
/* Initialization done */
|
||||
InterlockedExchange(&ThreadPoolInitialized,
|
||||
1);
|
||||
_InterlockedExchange(&ThreadPoolInitialized,
|
||||
1);
|
||||
break;
|
||||
}
|
||||
else if (InitStatus == 2)
|
||||
@@ -223,11 +223,11 @@ RtlpExecuteWorkItem(IN OUT PVOID NormalContext,
|
||||
}
|
||||
|
||||
/* update the requests counter */
|
||||
InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
|
||||
_InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
|
||||
|
||||
if (WorkItem.Flags & WT_EXECUTELONGFUNCTION)
|
||||
{
|
||||
InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
|
||||
_InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,11 +237,11 @@ RtlpQueueWorkerThread(IN OUT PRTLP_WORKITEM WorkItem)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
InterlockedIncrement(&ThreadPoolWorkerThreadsRequests);
|
||||
_InterlockedIncrement(&ThreadPoolWorkerThreadsRequests);
|
||||
|
||||
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION)
|
||||
{
|
||||
InterlockedIncrement(&ThreadPoolWorkerThreadsLongRequests);
|
||||
_InterlockedIncrement(&ThreadPoolWorkerThreadsLongRequests);
|
||||
}
|
||||
|
||||
if (WorkItem->Flags & WT_EXECUTEINPERSISTENTTHREAD)
|
||||
@@ -270,11 +270,11 @@ RtlpQueueWorkerThread(IN OUT PRTLP_WORKITEM WorkItem)
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
|
||||
_InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
|
||||
|
||||
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION)
|
||||
{
|
||||
InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
|
||||
_InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,11 +351,11 @@ RtlpExecuteIoWorkItem(IN OUT PVOID NormalContext,
|
||||
}
|
||||
|
||||
/* update the requests counter */
|
||||
InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
|
||||
_InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
|
||||
|
||||
if (WorkItem.Flags & WT_EXECUTELONGFUNCTION)
|
||||
{
|
||||
InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests);
|
||||
_InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,14 +461,14 @@ RtlpQueueIoWorkerThread(IN OUT PRTLP_WORKITEM WorkItem)
|
||||
|
||||
ASSERT(IoThread != NULL);
|
||||
|
||||
InterlockedIncrement(&ThreadPoolIOWorkerThreadsRequests);
|
||||
_InterlockedIncrement(&ThreadPoolIOWorkerThreadsRequests);
|
||||
|
||||
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION)
|
||||
{
|
||||
/* We're about to queue a long function, mark the thread */
|
||||
IoThread->Flags |= WT_EXECUTELONGFUNCTION;
|
||||
|
||||
InterlockedIncrement(&ThreadPoolIOWorkerThreadsLongRequests);
|
||||
_InterlockedIncrement(&ThreadPoolIOWorkerThreadsLongRequests);
|
||||
}
|
||||
|
||||
/* It's time to queue the work item */
|
||||
@@ -480,11 +480,11 @@ RtlpQueueIoWorkerThread(IN OUT PRTLP_WORKITEM WorkItem)
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to queue APC for work item 0x%p\n", WorkItem->Function);
|
||||
InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
|
||||
_InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
|
||||
|
||||
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION)
|
||||
{
|
||||
InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests);
|
||||
_InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ RtlpIoWorkerThreadProc(IN PVOID Parameter)
|
||||
BOOLEAN Terminate;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
if (InterlockedIncrement(&ThreadPoolIOWorkerThreads) > MAX_WORKERTHREADS)
|
||||
if (_InterlockedIncrement(&ThreadPoolIOWorkerThreads) > MAX_WORKERTHREADS)
|
||||
{
|
||||
/* Oops, too many worker threads... */
|
||||
goto InitFailed;
|
||||
@@ -562,10 +562,10 @@ RtlpIoWorkerThreadProc(IN PVOID Parameter)
|
||||
DPRINT1("Failed to create handle to own thread! Status: 0x%x\n", Status);
|
||||
|
||||
InitFailed:
|
||||
InterlockedDecrement(&ThreadPoolIOWorkerThreads);
|
||||
_InterlockedDecrement(&ThreadPoolIOWorkerThreads);
|
||||
|
||||
/* Signal initialization completion */
|
||||
InterlockedExchange((PLONG)Parameter,
|
||||
_InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
|
||||
RtlExitUserThread(Status);
|
||||
@@ -579,8 +579,8 @@ InitFailed:
|
||||
(PLIST_ENTRY)&ThreadInfo.ListEntry);
|
||||
|
||||
/* Signal initialization completion */
|
||||
InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
_InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@@ -626,7 +626,7 @@ Wait:
|
||||
if (Terminate)
|
||||
{
|
||||
/* Rundown the thread and unlink it from the list */
|
||||
InterlockedDecrement(&ThreadPoolIOWorkerThreads);
|
||||
_InterlockedDecrement(&ThreadPoolIOWorkerThreads);
|
||||
RemoveEntryList((PLIST_ENTRY)&ThreadInfo.ListEntry);
|
||||
}
|
||||
|
||||
@@ -663,11 +663,11 @@ RtlpWorkerThreadProc(IN PVOID Parameter)
|
||||
PKNORMAL_ROUTINE ApcRoutine;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
if (InterlockedIncrement(&ThreadPoolWorkerThreads) > MAX_WORKERTHREADS)
|
||||
if (_InterlockedIncrement(&ThreadPoolWorkerThreads) > MAX_WORKERTHREADS)
|
||||
{
|
||||
/* Signal initialization completion */
|
||||
InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
_InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
|
||||
/* Oops, too many worker threads... */
|
||||
RtlExitUserThread(Status);
|
||||
@@ -675,8 +675,8 @@ RtlpWorkerThreadProc(IN PVOID Parameter)
|
||||
}
|
||||
|
||||
/* Signal initialization completion */
|
||||
InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
_InterlockedExchange((PLONG)Parameter,
|
||||
1);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@@ -736,7 +736,7 @@ RtlpWorkerThreadProc(IN PVOID Parameter)
|
||||
|
||||
if (Terminate)
|
||||
{
|
||||
InterlockedDecrement(&ThreadPoolWorkerThreads);
|
||||
_InterlockedDecrement(&ThreadPoolWorkerThreads);
|
||||
Status = STATUS_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user