Author: tkreuzer Date: Thu Feb 10 11:47:17 2011 New Revision: 50648
URL: http://svn.reactos.org/svn/reactos?rev=50648&view=rev Log: [RTL] Merge changes to rtl from cmake branch. Mostly use portable interlocked functions
Modified: trunk/reactos/lib/rtl/actctx.c trunk/reactos/lib/rtl/critical.c trunk/reactos/lib/rtl/largeint.c trunk/reactos/lib/rtl/rtl.h trunk/reactos/lib/rtl/srw.c trunk/reactos/lib/rtl/timerqueue.c trunk/reactos/lib/rtl/vectoreh.c trunk/reactos/lib/rtl/wait.c trunk/reactos/lib/rtl/workitem.c
Modified: trunk/reactos/lib/rtl/actctx.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/actctx.c?rev=50648&... ============================================================================== --- trunk/reactos/lib/rtl/actctx.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/actctx.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -575,12 +575,12 @@
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;
Modified: trunk/reactos/lib/rtl/critical.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/critical.c?rev=5064... ============================================================================== --- trunk/reactos/lib/rtl/critical.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/critical.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -59,15 +59,15 @@
/* 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 (_InterlockedCompareExchangePointer((PVOID*)&CriticalSection->LockSemaphore, - (PVOID)hNewEvent, - 0)) { + if (InterlockedCompareExchangePointer((PVOID*)&CriticalSection->LockSemaphore, + (PVOID)hNewEvent, + 0)) {
/* Some just created an event */ DPRINT("Closing already created event: %p\n", hNewEvent); @@ -437,7 +437,7 @@ 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 @@ -621,7 +621,7 @@ if (--CriticalSection->RecursionCount) {
/* Someone still owns us, but we are free. This needs to be done atomically. */ - _InterlockedDecrement(&CriticalSection->LockCount); + InterlockedDecrement(&CriticalSection->LockCount);
} else {
@@ -630,7 +630,7 @@ 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); @@ -662,7 +662,7 @@ RtlTryEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection) { /* Try to take control */ - if (_InterlockedCompareExchange(&CriticalSection->LockCount, + if (InterlockedCompareExchange(&CriticalSection->LockCount, 0, -1) == -1) {
@@ -674,7 +674,7 @@ } else if (CriticalSection->OwningThread == NtCurrentTeb()->ClientId.UniqueThread) {
/* It's already ours */ - _InterlockedIncrement(&CriticalSection->LockCount); + InterlockedIncrement(&CriticalSection->LockCount); CriticalSection->RecursionCount++; return TRUE; }
Modified: trunk/reactos/lib/rtl/largeint.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/largeint.c?rev=5064... ============================================================================== --- trunk/reactos/lib/rtl/largeint.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/largeint.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -14,6 +14,40 @@
/* FUNCTIONS *****************************************************************/
+#undef RtlUlonglongByteSwap +#undef RtlUlongByteSwap +#undef RtlUshortByteSwap + +/* + * @implemented + */ +USHORT +FASTCALL +RtlUshortByteSwap(IN USHORT Source) +{ + return _byteswap_ushort(Source); +} + +/* + * @implemented + */ +ULONG +FASTCALL +RtlUlongByteSwap(IN ULONG Source) +{ + return _byteswap_ulong(Source); +} + +/* + * @implemented + */ +ULONGLONG +FASTCALL +RtlUlonglongByteSwap(IN ULONGLONG Source) +{ + return _byteswap_uint64(Source); +} + /* * @implemented */
Modified: trunk/reactos/lib/rtl/rtl.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/rtl.h?rev=50648&... ============================================================================== --- trunk/reactos/lib/rtl/rtl.h [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/rtl.h [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -32,6 +32,17 @@
#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 +#define InterlockedExchange _InterlockedExchange +#define InterlockedBitTestAndSet _interlockedbittestandset +#define InterlockedBitTestAndSet64 _interlockedbittestandset64 +#endif + #endif /* RTL_H */
/* EOF */
Modified: trunk/reactos/lib/rtl/srw.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/srw.c?rev=50648&... ============================================================================== --- trunk/reactos/lib/rtl/srw.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/srw.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -131,7 +131,7 @@ } }
- (void)_InterlockedExchangePointer(&SRWLock->Ptr, (PVOID)NewValue); + (void)InterlockedExchangePointer(&SRWLock->Ptr, (PVOID)NewValue);
if (FirstWaitBlock->Exclusive) { @@ -186,7 +186,7 @@ NewValue = RTL_SRWLOCK_OWNED; }
- (void)_InterlockedExchangePointer(&SRWLock->Ptr, (PVOID)NewValue); + (void)InterlockedExchangePointer(&SRWLock->Ptr, (PVOID)NewValue);
(void)InterlockedOr(&FirstWaitBlock->Wake, TRUE); @@ -420,9 +420,9 @@ NewValue = (CurrentValue >> RTL_SRWLOCK_BITS) + 1; NewValue = (NewValue << RTL_SRWLOCK_BITS) | (CurrentValue & RTL_SRWLOCK_MASK);
- if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* Successfully incremented the shared count, we acquired the lock */ break; @@ -499,9 +499,9 @@ ASSERT_SRW_WAITBLOCK(&StackWaitBlock);
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED; - if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { RtlpAcquireSRWLockSharedWait(SRWLock, &StackWaitBlock, @@ -521,9 +521,9 @@ RTL_SRWLOCK_SHARED nor the RTL_SRWLOCK_OWNED bit is set */ ASSERT(!(CurrentValue & RTL_SRWLOCK_CONTENDED));
- if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* Successfully set the shared count, we acquired the lock */ break; @@ -580,9 +580,9 @@ NewValue = (NewValue << RTL_SRWLOCK_BITS) | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_OWNED; }
- if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* Successfully released the lock */ break; @@ -639,9 +639,9 @@
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_CONTENDED | RTL_SRWLOCK_OWNED;
- if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { RtlpAcquireSRWLockExclusiveWait(SRWLock, &StackWaitBlock); @@ -697,9 +697,9 @@ ASSERT_SRW_WAITBLOCK(&StackWaitBlock);
NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED; - if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { RtlpAcquireSRWLockExclusiveWait(SRWLock, &StackWaitBlock); @@ -767,9 +767,9 @@ ASSERT(!(CurrentValue & ~RTL_SRWLOCK_OWNED));
NewValue = 0; - if ((LONG_PTR)_InterlockedCompareExchangePointer(&SRWLock->Ptr, - (PVOID)NewValue, - (PVOID)CurrentValue) == CurrentValue) + if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr, + (PVOID)NewValue, + (PVOID)CurrentValue) == CurrentValue) { /* We released the lock */ break;
Modified: trunk/reactos/lib/rtl/timerqueue.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/timerqueue.c?rev=50... ============================================================================== --- trunk/reactos/lib/rtl/timerqueue.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/timerqueue.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -372,7 +372,7 @@ 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. */
Modified: trunk/reactos/lib/rtl/vectoreh.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/vectoreh.c?rev=5064... ============================================================================== --- trunk/reactos/lib/rtl/vectoreh.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/vectoreh.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -61,7 +61,7 @@ if (--veh->Refs == 0) { RemoveEntryList (&veh->ListEntry); - _InterlockedDecrement (&RtlpVectoredExceptionsInstalled); + InterlockedDecrement (&RtlpVectoredExceptionsInstalled); Remove = TRUE; } Ret = TRUE; @@ -74,7 +74,7 @@ { CurrentEntry = veh->ListEntry.Flink; RemoveEntryList (&veh->ListEntry); - _InterlockedDecrement (&RtlpVectoredExceptionsInstalled); + InterlockedDecrement (&RtlpVectoredExceptionsInstalled); RtlLeaveCriticalSection(&RtlpVectoredExceptionLock);
RtlFreeHeap(RtlGetProcessHeap(), @@ -136,7 +136,7 @@ InsertTailList(&RtlpVectoredExceptionHead, &veh->ListEntry); } - _InterlockedIncrement (&RtlpVectoredExceptionsInstalled); + InterlockedIncrement (&RtlpVectoredExceptionsInstalled); RtlLeaveCriticalSection(&RtlpVectoredExceptionLock); }
@@ -190,4 +190,23 @@ return Ret; }
+PVOID +NTAPI +RtlAddVectoredContinueHandler( + IN ULONG FirstHandler, + IN PVECTORED_EXCEPTION_HANDLER VectoredHandler) +{ + UNIMPLEMENTED; + return NULL; +} + +ULONG +NTAPI +RtlRemoveVectoredContinueHandler( + IN PVOID VectoredHandlerHandle) +{ + UNIMPLEMENTED; + return FALSE; +} + /* EOF */
Modified: trunk/reactos/lib/rtl/wait.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/wait.c?rev=50648&am... ============================================================================== --- trunk/reactos/lib/rtl/wait.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/wait.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -91,7 +91,7 @@ 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 ); @@ -220,7 +220,7 @@ if (Status != STATUS_SUCCESS) return Status;
- (void)_InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent ); + (void)InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
if (Wait->CallbackInProgress) NtWaitForSingleObject( CompletionEvent, FALSE, NULL ); @@ -229,7 +229,7 @@ } else { - (void)_InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent ); + (void)InterlockedExchangePointer( &Wait->CompletionEvent, CompletionEvent );
if (Wait->CallbackInProgress) Status = STATUS_PENDING; @@ -239,7 +239,7 @@ Status = STATUS_PENDING; }
- if (_InterlockedIncrement( &Wait->DeleteCount ) == 2 ) + if (InterlockedIncrement( &Wait->DeleteCount ) == 2 ) { Status = STATUS_SUCCESS; NtClose( Wait->CancelEvent );
Modified: trunk/reactos/lib/rtl/workitem.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/workitem.c?rev=5064... ============================================================================== --- trunk/reactos/lib/rtl/workitem.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/workitem.c [iso-8859-1] Thu Feb 10 11:47:17 2011 @@ -55,7 +55,7 @@
do { - InitStatus = _InterlockedCompareExchange(&ThreadPoolInitialized, + InitStatus = InterlockedCompareExchange(&ThreadPoolInitialized, 2, 0); if (InitStatus == 0) @@ -91,7 +91,7 @@
Finish: /* Initialization done */ - _InterlockedExchange(&ThreadPoolInitialized, + InterlockedExchange(&ThreadPoolInitialized, 1); break; } @@ -223,11 +223,11 @@ }
/* update the requests counter */ - _InterlockedDecrement(&ThreadPoolWorkerThreadsRequests); + InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
if (WorkItem.Flags & WT_EXECUTELONGFUNCTION) { - _InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests); + InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests); } }
@@ -237,11 +237,11 @@ { 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 @@
if (!NT_SUCCESS(Status)) { - _InterlockedDecrement(&ThreadPoolWorkerThreadsRequests); + InterlockedDecrement(&ThreadPoolWorkerThreadsRequests);
if (WorkItem->Flags & WT_EXECUTELONGFUNCTION) { - _InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests); + InterlockedDecrement(&ThreadPoolWorkerThreadsLongRequests); } }
@@ -351,11 +351,11 @@ }
/* update the requests counter */ - _InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests); + InterlockedDecrement(&ThreadPoolIOWorkerThreadsRequests);
if (WorkItem.Flags & WT_EXECUTELONGFUNCTION) { - _InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests); + InterlockedDecrement(&ThreadPoolIOWorkerThreadsLongRequests); } }
@@ -461,14 +461,14 @@
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 @@ 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 @@ 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 @@ 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,7 +579,7 @@ (PLIST_ENTRY)&ThreadInfo.ListEntry);
/* Signal initialization completion */ - _InterlockedExchange((PLONG)Parameter, + InterlockedExchange((PLONG)Parameter, 1);
for (;;) @@ -626,7 +626,7 @@ if (Terminate) { /* Rundown the thread and unlink it from the list */ - _InterlockedDecrement(&ThreadPoolIOWorkerThreads); + InterlockedDecrement(&ThreadPoolIOWorkerThreads); RemoveEntryList((PLIST_ENTRY)&ThreadInfo.ListEntry); }
@@ -663,10 +663,10 @@ 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... */ @@ -675,7 +675,7 @@ }
/* Signal initialization completion */ - _InterlockedExchange((PLONG)Parameter, + InterlockedExchange((PLONG)Parameter, 1);
for (;;) @@ -736,7 +736,7 @@
if (Terminate) { - _InterlockedDecrement(&ThreadPoolWorkerThreads); + InterlockedDecrement(&ThreadPoolWorkerThreads); Status = STATUS_SUCCESS; break; }