- Use portable interlocked functions in code, define them to intrinsics for x86 and x64 in the header
svn path=/branches/cmake-bringup/; revision=49680
static inline void actctx_addref( ACTIVATION_CONTEXT *actctx )
{
- _InterlockedExchangeAdd( &actctx->ref_count, 1 );
+ InterlockedExchangeAdd( &actctx->ref_count, 1 );
}
static void actctx_release( ACTIVATION_CONTEXT *actctx )
{
- if (_InterlockedExchangeAdd( &actctx->ref_count, -1 ) == 1)
+ if (InterlockedExchangeAdd( &actctx->ref_count, -1 ) == 1)
{
unsigned int i, j;
/* We failed, this is bad... */
DPRINT1("Failed to Create Event!\n");
- _InterlockedDecrement(&CriticalSection->LockCount);
+ InterlockedDecrement(&CriticalSection->LockCount);
RtlRaiseStatus(Status);
return;
}
HANDLE Thread = (HANDLE)NtCurrentTeb()->ClientId.UniqueThread;
/* Try to Lock it */
- if (_InterlockedIncrement(&CriticalSection->LockCount) != 0) {
+ if (InterlockedIncrement(&CriticalSection->LockCount) != 0) {
/*
* We've failed to lock it! Does this thread
if (--CriticalSection->RecursionCount) {
/* Someone still owns us, but we are free. This needs to be done atomically. */
- _InterlockedDecrement(&CriticalSection->LockCount);
+ InterlockedDecrement(&CriticalSection->LockCount);
} else {
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);
RtlTryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
{
/* Try to take control */
- if (_InterlockedCompareExchange(&CriticalSection->LockCount,
+ if (InterlockedCompareExchange(&CriticalSection->LockCount,
0,
-1) == -1) {
} else if (CriticalSection->OwningThread == NtCurrentTeb()->ClientId.UniqueThread) {
/* It's already ours */
- _InterlockedIncrement(&CriticalSection->LockCount);
+ InterlockedIncrement(&CriticalSection->LockCount);
CriticalSection->RecursionCount++;
return TRUE;
}
#include <intrin.h>
+/* Use intrinsics for x86 and x64 */
+#if defined(_M_IX86) || defined(_M_AMD64)
+#define InterlockedCompareExchange _InterlockedCompareExchange
+#define InterlockedIncrement _InterlockedIncrement
+#define InterlockedDecrement _InterlockedDecrement
+#define InterlockedExchangeAdd _InterlockedExchangeAdd
+#endif
+
#endif /* RTL_H */
/* EOF */
}
}
- (void)_InterlockedExchange((PLONG)&SRWLock->Ptr, NewValue);
+ (void)InterlockedExchange((PLONG)&SRWLock->Ptr, NewValue);
if (FirstWaitBlock->Exclusive)
{
NewValue = RTL_SRWLOCK_OWNED;
}
- (void)_InterlockedExchange((PLONG)&SRWLock->Ptr, NewValue);
+ (void)InterlockedExchange((PLONG)&SRWLock->Ptr, NewValue);
(void)InterlockedOr(&FirstWaitBlock->Wake,
TRUE);
NewValue = (CurrentValue >> RTL_SRWLOCK_BITS) + 1;
NewValue = (NewValue << RTL_SRWLOCK_BITS) | (CurrentValue & RTL_SRWLOCK_MASK);
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
ASSERT_SRW_WAITBLOCK(&StackWaitBlock);
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED;
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
RTL_SRWLOCK_SHARED nor the RTL_SRWLOCK_OWNED bit is set */
ASSERT(!(CurrentValue & RTL_SRWLOCK_CONTENDED));
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
NewValue = (NewValue << RTL_SRWLOCK_BITS) | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_OWNED;
}
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_CONTENDED | RTL_SRWLOCK_OWNED;
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
ASSERT_SRW_WAITBLOCK(&StackWaitBlock);
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED;
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
ASSERT(!(CurrentValue & ~RTL_SRWLOCK_OWNED));
NewValue = 0;
- if (_InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
+ if (InterlockedCompareExchange((PLONG)&SRWLock->Ptr,
NewValue,
CurrentValue) == CurrentValue)
{
NTSTATUS status = RtlCreateTimerQueue(&q);
if (status == STATUS_SUCCESS)
{
- PVOID p = _InterlockedCompareExchangePointer(
+ PVOID p = InterlockedCompareExchangePointer(
(void **) &default_timer_queue, q, NULL);
if (p)
/* Got beat to the punch. */
if (--veh->Refs == 0)
{
RemoveEntryList (&veh->ListEntry);
- _InterlockedDecrement (&RtlpVectoredExceptionsInstalled);
+ InterlockedDecrement (&RtlpVectoredExceptionsInstalled);
Remove = TRUE;
}
Ret = TRUE;
{
CurrentEntry = veh->ListEntry.Flink;
RemoveEntryList (&veh->ListEntry);
- _InterlockedDecrement (&RtlpVectoredExceptionsInstalled);
+ InterlockedDecrement (&RtlpVectoredExceptionsInstalled);
RtlLeaveCriticalSection(&RtlpVectoredExceptionLock);
RtlFreeHeap(RtlGetProcessHeap(),
InsertTailList(&RtlpVectoredExceptionHead,
&veh->ListEntry);
}
- _InterlockedIncrement (&RtlpVectoredExceptionsInstalled);
+ InterlockedIncrement (&RtlpVectoredExceptionsInstalled);
RtlLeaveCriticalSection(&RtlpVectoredExceptionLock);
}
completion_event = Wait->CompletionEvent;
if (completion_event) NtSetEvent( completion_event, NULL );
- if (_InterlockedIncrement( &Wait->DeleteCount ) == 2 )
+ if (InterlockedIncrement( &Wait->DeleteCount ) == 2 )
{
NtClose( Wait->CancelEvent );
RtlFreeHeap( RtlGetProcessHeap(), 0, Wait );
if (Status != STATUS_SUCCESS)
return Status;
- (void)_InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
+ (void)InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
if (Wait->CallbackInProgress)
NtWaitForSingleObject( CompletionEvent, FALSE, NULL );
}
else
{
- (void)_InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
+ (void)InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
if (Wait->CallbackInProgress)
Status = STATUS_PENDING;
Status = STATUS_PENDING;
}
- if (_InterlockedIncrement( &Wait->DeleteCount ) == 2 )
+ if (InterlockedIncrement( &Wait->DeleteCount ) == 2 )
{
Status = STATUS_SUCCESS;
NtClose( Wait->CancelEvent );
do
{
- InitStatus = _InterlockedCompareExchange(&ThreadPoolInitialized,
+ InitStatus = InterlockedCompareExchange(&ThreadPoolInitialized,
2,
0);
if (InitStatus == 0)
Finish:
/* Initialization done */
- _InterlockedExchange(&ThreadPoolInitialized,
+ InterlockedExchange(&ThreadPoolInitialized,
1);
break;
}
}
/* update the requests counter */
- _InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
+ InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
if (WorkItem.Flags & WT_EXECUTELONGFUNCTION)
{
- _InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
+ InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
}
}
{
NTSTATUS Status = STATUS_SUCCESS;
- _InterlockedIncrement(&ThreadPoolWorkerThreadsRequests);
+ InterlockedIncrement(&ThreadPoolWorkerThreadsRequests);
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION)
{
- _InterlockedIncrement(&ThreadPoolWorkerThreadsLongRequests);
+ InterlockedIncrement(&ThreadPoolWorkerThreadsLongRequests);
}
if (WorkItem->Flags & WT_EXECUTEINPERSISTENTTHREAD)
if (!NT_SUCCESS(Status))
{
- _InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
+ InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION)
{
- _InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
+ InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests);
}
}
}
/* update the requests counter */
- _InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
+ InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
if (WorkItem.Flags & WT_EXECUTELONGFUNCTION)
{
- _InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests);
+ InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests);
}
}
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 */
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);
}
}
BOOLEAN Terminate;
NTSTATUS Status = STATUS_SUCCESS;
- if (_InterlockedIncrement(&ThreadPoolIOWorkerThreads) > MAX_WORKERTHREADS)
+ if (InterlockedIncrement(&ThreadPoolIOWorkerThreads) > MAX_WORKERTHREADS)
{
/* Oops, too many worker threads... */
goto InitFailed;
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);
(PLIST_ENTRY)&ThreadInfo.ListEntry);
/* Signal initialization completion */
- _InterlockedExchange((PLONG)Parameter,
+ InterlockedExchange((PLONG)Parameter,
1);
for (;;)
if (Terminate)
{
/* Rundown the thread and unlink it from the list */
- _InterlockedDecrement(&ThreadPoolIOWorkerThreads);
+ InterlockedDecrement(&ThreadPoolIOWorkerThreads);
RemoveEntryList((PLIST_ENTRY)&ThreadInfo.ListEntry);
}
PKNORMAL_ROUTINE ApcRoutine;
NTSTATUS Status = STATUS_SUCCESS;
- if (_InterlockedIncrement(&ThreadPoolWorkerThreads) > MAX_WORKERTHREADS)
+ if (InterlockedIncrement(&ThreadPoolWorkerThreads) > MAX_WORKERTHREADS)
{
/* Signal initialization completion */
- _InterlockedExchange((PLONG)Parameter,
+ InterlockedExchange((PLONG)Parameter,
1);
/* Oops, too many worker threads... */
}
/* Signal initialization completion */
- _InterlockedExchange((PLONG)Parameter,
+ InterlockedExchange((PLONG)Parameter,
1);
for (;;)
if (Terminate)
{
- _InterlockedDecrement(&ThreadPoolWorkerThreads);
+ InterlockedDecrement(&ThreadPoolWorkerThreads);
Status = STATUS_SUCCESS;
break;
}