From e2de2a461088ebee78786582e42fa7312888bd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 5 Oct 2013 20:06:47 +0000 Subject: [PATCH] [CSRSRV] - Do not associate the newly created wait block to the waiting thread (in CsrInitializeWait) in case this one is going to terminate, but do it instead in CsrCreateWait, where the check actually takes place. - Avoid PPORT_MESSAGE casts. - Fix a list insertion problem in CsrMoveSatisfiedWait. - Fix some descriptions / comments. svn path=/trunk/; revision=60541 --- reactos/include/reactos/subsys/csr/csrsrv.h | 2 +- reactos/subsystems/win32/csrsrv/wait.c | 40 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/reactos/include/reactos/subsys/csr/csrsrv.h b/reactos/include/reactos/subsys/csr/csrsrv.h index 2ed03b3b4ba..a8bf5d2013d 100644 --- a/reactos/include/reactos/subsys/csr/csrsrv.h +++ b/reactos/include/reactos/subsys/csr/csrsrv.h @@ -343,7 +343,7 @@ CsrLockThreadByClientId(IN HANDLE Tid, VOID NTAPI -CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry, +CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList, IN PLIST_ENTRY WaitList); BOOLEAN diff --git a/reactos/subsystems/win32/csrsrv/wait.c b/reactos/subsystems/win32/csrsrv/wait.c index 40f9d575ae8..faff1782b6a 100644 --- a/reactos/subsystems/win32/csrsrv/wait.c +++ b/reactos/subsystems/win32/csrsrv/wait.c @@ -71,11 +71,10 @@ CsrInitializeWait(IN CSR_WAIT_FUNCTION WaitFunction, } /* Initialize it */ - WaitBlock->Size = Size; - WaitBlock->WaitThread = CsrWaitThread; - CsrWaitThread->WaitBlock = WaitBlock; - WaitBlock->WaitContext = WaitContext; - WaitBlock->WaitFunction = WaitFunction; + WaitBlock->Size = Size; + WaitBlock->WaitThread = CsrWaitThread; + WaitBlock->WaitContext = WaitContext; + WaitBlock->WaitFunction = WaitFunction; WaitBlock->WaitList.Flink = NULL; WaitBlock->WaitList.Blink = NULL; @@ -96,7 +95,7 @@ CsrInitializeWait(IN CSR_WAIT_FUNCTION WaitFunction, * CSR Wait Block, and replies to the attached CSR API Message, if any. * * @param WaitBlock - * Pointer to the CSR Wait Block + * Pointer to the CSR Wait Block. * * @param WaitList * Pointer to the wait list for this wait. @@ -146,7 +145,7 @@ CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock, /* Reply to the port */ NtReplyPort(WaitBlock->WaitThread->Process->ClientPort, - (PPORT_MESSAGE)&WaitBlock->WaitApiMessage); + &WaitBlock->WaitApiMessage.Header); /* Check if we should dereference the thread */ if (DereferenceThread) @@ -186,7 +185,7 @@ CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock, * The CsrCreateWait routine creates a CSR Wait. * * @param WaitList - * Pointer to a list entry of the waits to associate. + * Pointer to a wait list in which the wait will be added. * * @param WaitFunction * Pointer to the function that will handle this wait. @@ -232,12 +231,14 @@ CsrCreateWait(IN PLIST_ENTRY WaitList, if (CsrWaitThread->Flags & CsrThreadTerminated) { /* Fail the wait */ - CsrWaitThread->WaitBlock = NULL; RtlFreeHeap(CsrHeap, 0, WaitBlock); CsrReleaseWaitLock(); return FALSE; } + /* Associate the newly created wait to the waiting thread */ + CsrWaitThread->WaitBlock = WaitBlock; + /* Insert the wait in the queue */ InsertTailList(WaitList, &WaitBlock->WaitList); @@ -309,14 +310,15 @@ CsrDereferenceWait(IN PLIST_ENTRY WaitList) * @name CsrMoveSatisfiedWait * @implemented NT5 * - * The CsrMoveSatisfiedWait routine moves satisfied waits from a wait list - * to another list entry. + * The CsrMoveSatisfiedWait routine moves satisfied waits from + * a wait list to another list. * - * @param NewEntry - * Pointer to a list entry where the satisfied waits will be added. + * @param DestinationList + * Pointer to a list in which the satisfied waits will be added. * * @param WaitList - * Pointer to a list entry to analyze for satisfied waits. + * Pointer to the wait list whose satisfied wait blocks + * will be moved away. * * @return None. * @@ -325,7 +327,7 @@ CsrDereferenceWait(IN PLIST_ENTRY WaitList) *--*/ VOID NTAPI -CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry, +CsrMoveSatisfiedWait(IN PLIST_ENTRY DestinationList, IN PLIST_ENTRY WaitList) { PLIST_ENTRY NextEntry; @@ -352,8 +354,8 @@ CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry, /* Remove it from the Wait Block Queue */ RemoveEntryList(&WaitBlock->WaitList); - /* Insert the new entry */ - InsertTailList(&WaitBlock->WaitList, NewEntry); + /* Insert the wait into the destination list */ + InsertTailList(DestinationList, &WaitBlock->WaitList); } } @@ -365,10 +367,10 @@ CsrMoveSatisfiedWait(IN PLIST_ENTRY NewEntry, * @name CsrNotifyWait * @implemented NT4 * - * The CsrNotifyWait notifies a CSR Wait Block. + * The CsrNotifyWait notifies CSR Wait Blocks. * * @param WaitList - * Pointer to the list entry for this wait. + * Pointer to the wait list whose wait blocks will be notified. * * @param WaitType * Type of the wait to perform, either WaitAny or WaitAll.