Author: ion Date: Sat Jul 15 01:45:27 2006 New Revision: 23063
URL: http://svn.reactos.org/svn/reactos?rev=23063&view=rev Log: - Add IN/OUT annotations for KeWaitForSIngleObject - Set the wait block outside the loop, small optimization in case we get alerted by an APC and have to loop again. - Set the wait block pointer in the KTHREAD structure only *after* checking if a wait is actually needed. That way, if the object is already signaled, we don't set anything in the WaitBlockList. - Small optimization: only set the caller's WAitBlock as the next wait block if a timer wasn't specificed, else we ended up overwriting the value. - Small optimziation: don't write the thread in the wait block, this is a wait for a signle object so this isn't needed.
Modified: trunk/reactos/ntoskrnl/ke/wait.c
Modified: trunk/reactos/ntoskrnl/ke/wait.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/wait.c?rev=2306... ============================================================================== --- trunk/reactos/ntoskrnl/ke/wait.c (original) +++ trunk/reactos/ntoskrnl/ke/wait.c Sat Jul 15 01:45:27 2006 @@ -379,11 +379,11 @@ */ NTSTATUS NTAPI -KeWaitForSingleObject(PVOID Object, - KWAIT_REASON WaitReason, - KPROCESSOR_MODE WaitMode, - BOOLEAN Alertable, - PLARGE_INTEGER Timeout) +KeWaitForSingleObject(IN PVOID Object, + IN KWAIT_REASON WaitReason, + IN KPROCESSOR_MODE WaitMode, + IN BOOLEAN Alertable, + IN PLARGE_INTEGER Timeout OPTIONAL) { PKMUTANT CurrentObject; PKWAIT_BLOCK WaitBlock; @@ -406,6 +406,7 @@ }
/* Start the actual Loop */ + WaitBlock = &CurrentThread->WaitBlock[0]; do { /* Check if a kernel APC is pending and we're below APC_LEVEL */ @@ -420,10 +421,6 @@ { /* Set default status */ CurrentThread->WaitStatus = STATUS_WAIT_0; - - /* Append wait block to the KTHREAD wait block list */ - WaitBlock = &CurrentThread->WaitBlock[0]; - CurrentThread->WaitBlockList = WaitBlock;
/* Get the Current Object */ CurrentObject = (PKMUTANT)Object; @@ -460,12 +457,13 @@ goto DontWait; }
+ /* Append wait block to the KTHREAD wait block list */ + CurrentThread->WaitBlockList = WaitBlock; + /* Set up the Wait Block */ WaitBlock->Object = CurrentObject; - WaitBlock->Thread = CurrentThread; WaitBlock->WaitKey = (USHORT)(STATUS_SUCCESS); WaitBlock->WaitType = WaitAny; - WaitBlock->NextWaitBlock = WaitBlock;
/* Make sure we can satisfy the Alertable request */ KiCheckAlertability(); @@ -508,6 +506,11 @@ WaitStatus = STATUS_TIMEOUT; goto DontWait; } + } + else + { + /* No timer block, so just set our wait block as next */ + WaitBlock->NextWaitBlock = WaitBlock; }
/* Link the Object to this Wait Block */