Author: tkreuzer Date: Sun Jul 28 10:41:27 2013 New Revision: 59591 URL: http://svn.reactos.org/svn/reactos?rev=59591&view=rev Log: [CSRSRV] - Reduce number of hash collisions during bootup from 10 to 0, by choosing 257 (prime number = good) instead of 256 (power of 2 = bad) - Use ULONG for CsrpStaticThreadCount and CsrpDynamicThreadTotal to fix an MSVC warning.
Modified: trunk/reactos/subsystems/win32/csrsrv/api.c trunk/reactos/subsystems/win32/csrsrv/api.h trunk/reactos/subsystems/win32/csrsrv/srv.h trunk/reactos/subsystems/win32/csrsrv/thredsup.c Modified: trunk/reactos/subsystems/win32/csrsrv/api.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/api.c?rev=59591&r1=59590&r2=59591&view=diff ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/api.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/api.c [iso-8859-1] Sun Jul 28 10:41:27 2013 @@ -18,8 +18,8 @@ BOOLEAN (*CsrClientThreadSetup)(VOID) = NULL; UNICODE_STRING CsrApiPortName; -volatile LONG CsrpStaticThreadCount; -volatile LONG CsrpDynamicThreadTotal; +volatile ULONG CsrpStaticThreadCount; +volatile ULONG CsrpDynamicThreadTotal; extern ULONG CsrMaxApiRequestThreads; /* FUNCTIONS ******************************************************************/ @@ -269,7 +269,7 @@ NTSTATUS Status; /* Decrease the count, and see if we're out */ - if (_InterlockedDecrement(&CsrpStaticThreadCount) == 0) + if (InterlockedDecrementUL(&CsrpStaticThreadCount) == 0) { /* Check if we've still got space for a Dynamic Thread */ if (CsrpDynamicThreadTotal < CsrMaxApiRequestThreads) @@ -289,8 +289,8 @@ if (NT_SUCCESS(Status)) { /* Increase the thread counts */ - _InterlockedIncrement(&CsrpStaticThreadCount); - _InterlockedIncrement(&CsrpDynamicThreadTotal); + InterlockedIncrementUL(&CsrpStaticThreadCount); + InterlockedIncrementUL(&CsrpDynamicThreadTotal); /* Add a new server thread */ if (CsrAddStaticServerThread(hThread, @@ -303,8 +303,8 @@ else { /* Failed to create a new static thread */ - _InterlockedDecrement(&CsrpStaticThreadCount); - _InterlockedDecrement(&CsrpDynamicThreadTotal); + InterlockedDecrementUL(&CsrpStaticThreadCount); + InterlockedDecrementUL(&CsrpDynamicThreadTotal); /* Terminate it */ DPRINT1("Failing\n"); @@ -383,8 +383,8 @@ ASSERT(NT_SUCCESS(Status)); /* Increase the Thread Counts */ - _InterlockedIncrement(&CsrpStaticThreadCount); - _InterlockedIncrement(&CsrpDynamicThreadTotal); + InterlockedIncrementUL(&CsrpStaticThreadCount); + InterlockedIncrementUL(&CsrpDynamicThreadTotal); } /* Now start the loop */ @@ -513,7 +513,7 @@ } /* Increase the thread count */ - _InterlockedIncrement(&CsrpStaticThreadCount); + InterlockedIncrementUL(&CsrpStaticThreadCount); /* If the response was 0xFFFFFFFF, we'll ignore it */ if (HardErrorMsg->Response == 0xFFFFFFFF) @@ -595,7 +595,7 @@ ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode); /* Increase the static thread count */ - _InterlockedIncrement(&CsrpStaticThreadCount); + InterlockedIncrementUL(&CsrpStaticThreadCount); } _SEH2_EXCEPT(CsrUnhandledExceptionFilter(_SEH2_GetExceptionInformation())) { @@ -706,7 +706,7 @@ } /* Increase the thread count */ - _InterlockedIncrement(&CsrpStaticThreadCount); + InterlockedIncrementUL(&CsrpStaticThreadCount); /* If the response was 0xFFFFFFFF, we'll ignore it */ if (HardErrorMsg->Response == 0xFFFFFFFF) @@ -818,7 +818,7 @@ ReplyMsg->Status = ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode); /* Increase the static thread count */ - _InterlockedIncrement(&CsrpStaticThreadCount); + InterlockedIncrementUL(&CsrpStaticThreadCount); Teb->CsrClientThread = CurrentThread; Modified: trunk/reactos/subsystems/win32/csrsrv/api.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/api.h?rev=59591&r1=59590&r2=59591&view=diff ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/api.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/api.h [iso-8859-1] Sun Jul 28 10:41:27 2013 @@ -45,7 +45,7 @@ extern HANDLE CsrApiPort; extern HANDLE CsrSmApiPort; extern HANDLE CsrSbApiPort; -extern LIST_ENTRY CsrThreadHashTable[256]; +extern LIST_ENTRY CsrThreadHashTable[257]; extern PCSR_PROCESS CsrRootProcess; extern UNICODE_STRING CsrDirectoryName; extern ULONG CsrDebug; Modified: trunk/reactos/subsystems/win32/csrsrv/srv.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/srv.h?rev=59591&r1=59590&r2=59591&view=diff ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/srv.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/srv.h [iso-8859-1] Sun Jul 28 10:41:27 2013 @@ -55,6 +55,8 @@ #define ROUND_UP(n, align) ROUND_DOWN(((ULONG)n) + (align) - 1, (align)) #define ROUND_DOWN(n, align) (((ULONG)n) & ~((align) - 1l)) +#define InterlockedIncrementUL(Value) _InterlockedIncrement((PLONG)Value) +#define InterlockedDecrementUL(Value) _InterlockedDecrement((PLONG)Value) #endif // _SRV_H Modified: trunk/reactos/subsystems/win32/csrsrv/thredsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrsrv/thredsup.c?rev=59591&r1=59590&r2=59591&view=diff ============================================================================== --- trunk/reactos/subsystems/win32/csrsrv/thredsup.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrsrv/thredsup.c [iso-8859-1] Sun Jul 28 10:41:27 2013 @@ -14,11 +14,11 @@ #define NDEBUG #include <debug.h> -#define CsrHashThread(t) (HandleToUlong(t)&(256 - 1)) +#define CsrHashThread(t) (HandleToUlong(t) % 257) /* GLOBALS ********************************************************************/ -LIST_ENTRY CsrThreadHashTable[256]; +LIST_ENTRY CsrThreadHashTable[257]; /* PRIVATE FUNCTIONS **********************************************************/ @@ -581,7 +581,7 @@ DPRINT1("No known process for %lx\n", ClientId->UniqueProcess); return Status; } - + /* Make sure the thread didn't terminate */ if (KernelTimes.ExitTime.QuadPart) {