mirror of
https://github.com/reactos/reactos.git
synced 2025-02-25 01:39:30 +00:00
- Set the right Thread->WaitTime dring waits
- Initialize WaitBlock->Thread during thread creation. - Make APCs queuable for the thread after it's created - Enable Timer Block optimization since it works now. This allows us not to always set-up for each wait, since most of its fields can remain static. - Properly link wait block together with the waitlist of the timer. svn path=/trunk/; revision=20632
This commit is contained in:
parent
357c1b2aa4
commit
3a24f9a505
4 changed files with 39 additions and 38 deletions
|
@ -63,13 +63,12 @@ KeWaitForGate(PKGATE Gate,
|
||||||
GateWaitBlock->Thread = CurrentThread;
|
GateWaitBlock->Thread = CurrentThread;
|
||||||
|
|
||||||
/* Set the Thread Wait Data */
|
/* Set the Thread Wait Data */
|
||||||
CurrentThread->WaitReason = WaitReason;
|
|
||||||
CurrentThread->WaitMode = WaitMode;
|
|
||||||
CurrentThread->WaitIrql = OldIrql;
|
CurrentThread->WaitIrql = OldIrql;
|
||||||
CurrentThread->GateObject = Gate;
|
CurrentThread->GateObject = Gate;
|
||||||
|
|
||||||
/* Insert into the Wait List */
|
/* Insert into the Wait List */
|
||||||
InsertTailList(&Gate->Header.WaitListHead, &GateWaitBlock->WaitListEntry);
|
InsertTailList(&Gate->Header.WaitListHead,
|
||||||
|
&GateWaitBlock->WaitListEntry);
|
||||||
|
|
||||||
/* Handle Kernel Queues */
|
/* Handle Kernel Queues */
|
||||||
if (CurrentThread->Queue)
|
if (CurrentThread->Queue)
|
||||||
|
@ -81,7 +80,7 @@ KeWaitForGate(PKGATE Gate,
|
||||||
/* Setup the wait information */
|
/* Setup the wait information */
|
||||||
CurrentThread->WaitMode = WaitMode;
|
CurrentThread->WaitMode = WaitMode;
|
||||||
CurrentThread->WaitReason = WaitReason;
|
CurrentThread->WaitReason = WaitReason;
|
||||||
CurrentThread->WaitTime = 0;
|
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
|
||||||
CurrentThread->State = Waiting;
|
CurrentThread->State = Waiting;
|
||||||
|
|
||||||
/* Find a new thread to run */
|
/* Find a new thread to run */
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#define THREAD_ALERT_INCREMENT 2
|
#define THREAD_ALERT_INCREMENT 2
|
||||||
|
|
||||||
extern EX_WORK_QUEUE ExWorkerQueue[MaximumWorkQueue];
|
extern EX_WORK_QUEUE ExWorkerQueue[MaximumWorkQueue];
|
||||||
|
#define TIMER_WAIT_BLOCK 0x3L
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PURPOSE: List of threads associated with each priority level
|
* PURPOSE: List of threads associated with each priority level
|
||||||
|
@ -789,6 +791,10 @@ KeInitializeThread(PKPROCESS Process,
|
||||||
PVOID Teb,
|
PVOID Teb,
|
||||||
PVOID KernelStack)
|
PVOID KernelStack)
|
||||||
{
|
{
|
||||||
|
ULONG i;
|
||||||
|
PKWAIT_BLOCK TimerWaitBlock;
|
||||||
|
PKTIMER Timer;
|
||||||
|
|
||||||
/* Initalize the Dispatcher Header */
|
/* Initalize the Dispatcher Header */
|
||||||
DPRINT("Initializing Dispatcher Header for New Thread: %x in Process: %x\n", Thread, Process);
|
DPRINT("Initializing Dispatcher Header for New Thread: %x in Process: %x\n", Thread, Process);
|
||||||
KeInitializeDispatcherHeader(&Thread->DispatcherHeader,
|
KeInitializeDispatcherHeader(&Thread->DispatcherHeader,
|
||||||
|
@ -803,6 +809,13 @@ KeInitializeThread(PKPROCESS Process,
|
||||||
/* Initialize the Mutant List */
|
/* Initialize the Mutant List */
|
||||||
InitializeListHead(&Thread->MutantListHead);
|
InitializeListHead(&Thread->MutantListHead);
|
||||||
|
|
||||||
|
/* Initialize the wait blocks */
|
||||||
|
for (i = 0; i< (THREAD_WAIT_OBJECTS + 1); i++)
|
||||||
|
{
|
||||||
|
/* Put our pointer */
|
||||||
|
Thread->WaitBlock[i].Thread = Thread;
|
||||||
|
}
|
||||||
|
|
||||||
/* Setup the Service Descriptor Table for Native Calls */
|
/* Setup the Service Descriptor Table for Native Calls */
|
||||||
Thread->ServiceTable = KeServiceDescriptorTable;
|
Thread->ServiceTable = KeServiceDescriptorTable;
|
||||||
|
|
||||||
|
@ -813,6 +826,7 @@ KeInitializeThread(PKPROCESS Process,
|
||||||
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
|
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
|
||||||
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
|
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
|
||||||
Thread->ApcStateIndex = OriginalApcEnvironment;
|
Thread->ApcStateIndex = OriginalApcEnvironment;
|
||||||
|
Thread->ApcQueueable = TRUE;
|
||||||
KeInitializeSpinLock(&Thread->ApcQueueLock);
|
KeInitializeSpinLock(&Thread->ApcQueueLock);
|
||||||
|
|
||||||
/* Initialize the Suspend APC */
|
/* Initialize the Suspend APC */
|
||||||
|
@ -829,16 +843,17 @@ KeInitializeThread(PKPROCESS Process,
|
||||||
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 128);
|
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 128);
|
||||||
|
|
||||||
/* FIXME OPTIMIZATION OF DOOM. DO NOT ENABLE FIXME */
|
/* FIXME OPTIMIZATION OF DOOM. DO NOT ENABLE FIXME */
|
||||||
#if 0
|
Timer = &Thread->Timer;
|
||||||
Thread->WaitBlock[3].Object = (PVOID)&Thread->Timer;
|
KeInitializeTimer(Timer);
|
||||||
Thread->WaitBlock[3].Thread = Thread;
|
TimerWaitBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
|
||||||
Thread->WaitBlock[3].WaitKey = STATUS_TIMEOUT;
|
TimerWaitBlock->Object = Timer;
|
||||||
Thread->WaitBlock[3].WaitType = WaitAny;
|
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
|
||||||
Thread->WaitBlock[3].NextWaitBlock = NULL;
|
TimerWaitBlock->WaitType = WaitAny;
|
||||||
InsertTailList(&Thread->Timer.Header.WaitListHead,
|
TimerWaitBlock->NextWaitBlock = NULL;
|
||||||
&Thread->WaitBlock[3].WaitListEntry);
|
|
||||||
#endif
|
/* Link the two wait lists together */
|
||||||
KeInitializeTimer(&Thread->Timer);
|
TimerWaitBlock->WaitListEntry.Flink = &Timer->Header.WaitListHead;
|
||||||
|
TimerWaitBlock->WaitListEntry.Blink = &Timer->Header.WaitListHead;
|
||||||
|
|
||||||
/* Set the TEB */
|
/* Set the TEB */
|
||||||
Thread->Teb = Teb;
|
Thread->Teb = Teb;
|
||||||
|
|
|
@ -270,8 +270,8 @@ KeRemoveQueue(IN PKQUEUE Queue,
|
||||||
WaitBlock->WaitType = WaitAny;
|
WaitBlock->WaitType = WaitAny;
|
||||||
|
|
||||||
/* Link the timer to this Wait Block */
|
/* Link the timer to this Wait Block */
|
||||||
InitializeListHead(&Timer->Header.WaitListHead);
|
Timer->Header.WaitListHead.Flink = &WaitBlock->WaitListEntry;
|
||||||
InsertTailList(&Timer->Header.WaitListHead, &WaitBlock->WaitListEntry);
|
Timer->Header.WaitListHead.Blink = &WaitBlock->WaitListEntry;
|
||||||
|
|
||||||
/* Create Timer */
|
/* Create Timer */
|
||||||
DPRINT("Creating Timer with timeout %I64d\n", *Timeout);
|
DPRINT("Creating Timer with timeout %I64d\n", *Timeout);
|
||||||
|
@ -290,7 +290,7 @@ KeRemoveQueue(IN PKQUEUE Queue,
|
||||||
Thread->WaitMode = WaitMode;
|
Thread->WaitMode = WaitMode;
|
||||||
Thread->WaitReason = WrQueue;
|
Thread->WaitReason = WrQueue;
|
||||||
Thread->Alertable = FALSE;
|
Thread->Alertable = FALSE;
|
||||||
Thread->WaitTime = 0;
|
Thread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
|
||||||
Thread->State = Waiting;
|
Thread->State = Waiting;
|
||||||
|
|
||||||
/* Find a new thread to run */
|
/* Find a new thread to run */
|
||||||
|
|
|
@ -148,15 +148,11 @@ KeDelayExecutionThread(KPROCESSOR_MODE WaitMode,
|
||||||
|
|
||||||
/* Setup the Wait Block */
|
/* Setup the Wait Block */
|
||||||
CurrentThread->WaitBlockList = TimerWaitBlock;
|
CurrentThread->WaitBlockList = TimerWaitBlock;
|
||||||
TimerWaitBlock->Object = (PVOID)ThreadTimer;
|
|
||||||
TimerWaitBlock->Thread = CurrentThread;
|
|
||||||
TimerWaitBlock->WaitKey = (USHORT)STATUS_TIMEOUT;
|
|
||||||
TimerWaitBlock->WaitType = WaitAny;
|
|
||||||
TimerWaitBlock->NextWaitBlock = TimerWaitBlock;
|
TimerWaitBlock->NextWaitBlock = TimerWaitBlock;
|
||||||
|
|
||||||
/* Link the timer to this Wait Block */
|
/* Link the timer to this Wait Block */
|
||||||
InitializeListHead(&ThreadTimer->Header.WaitListHead);
|
ThreadTimer->Header.WaitListHead.Flink = &TimerWaitBlock->WaitListEntry;
|
||||||
InsertTailList(&ThreadTimer->Header.WaitListHead, &TimerWaitBlock->WaitListEntry);
|
ThreadTimer->Header.WaitListHead.Blink = &TimerWaitBlock->WaitListEntry;
|
||||||
|
|
||||||
/* Insert the Timer into the Timer Lists and enable it */
|
/* Insert the Timer into the Timer Lists and enable it */
|
||||||
if (!KiInsertTimer(ThreadTimer, *Interval))
|
if (!KiInsertTimer(ThreadTimer, *Interval))
|
||||||
|
@ -177,7 +173,7 @@ KeDelayExecutionThread(KPROCESSOR_MODE WaitMode,
|
||||||
CurrentThread->Alertable = Alertable;
|
CurrentThread->Alertable = Alertable;
|
||||||
CurrentThread->WaitMode = WaitMode;
|
CurrentThread->WaitMode = WaitMode;
|
||||||
CurrentThread->WaitReason = DelayExecution;
|
CurrentThread->WaitReason = DelayExecution;
|
||||||
CurrentThread->WaitTime = 0;
|
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
|
||||||
CurrentThread->State = Waiting;
|
CurrentThread->State = Waiting;
|
||||||
|
|
||||||
/* Find a new thread to run */
|
/* Find a new thread to run */
|
||||||
|
@ -336,16 +332,11 @@ KeWaitForSingleObject(PVOID Object,
|
||||||
WaitBlock->NextWaitBlock = TimerWaitBlock;
|
WaitBlock->NextWaitBlock = TimerWaitBlock;
|
||||||
|
|
||||||
/* Set up the Timer Wait Block */
|
/* Set up the Timer Wait Block */
|
||||||
TimerWaitBlock->Object = (PVOID)ThreadTimer;
|
|
||||||
TimerWaitBlock->Thread = CurrentThread;
|
|
||||||
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
|
|
||||||
TimerWaitBlock->WaitType = WaitAny;
|
|
||||||
TimerWaitBlock->NextWaitBlock = WaitBlock;
|
TimerWaitBlock->NextWaitBlock = WaitBlock;
|
||||||
|
|
||||||
/* Link the timer to this Wait Block */
|
/* Link the timer to this Wait Block */
|
||||||
InitializeListHead(&ThreadTimer->Header.WaitListHead);
|
ThreadTimer->Header.WaitListHead.Flink = &TimerWaitBlock->WaitListEntry;
|
||||||
InsertTailList(&ThreadTimer->Header.WaitListHead,
|
ThreadTimer->Header.WaitListHead.Blink = &TimerWaitBlock->WaitListEntry;
|
||||||
&TimerWaitBlock->WaitListEntry);
|
|
||||||
|
|
||||||
/* Insert the Timer into the Timer Lists and enable it */
|
/* Insert the Timer into the Timer Lists and enable it */
|
||||||
if (!KiInsertTimer(ThreadTimer, *Timeout))
|
if (!KiInsertTimer(ThreadTimer, *Timeout))
|
||||||
|
@ -371,7 +362,7 @@ KeWaitForSingleObject(PVOID Object,
|
||||||
CurrentThread->Alertable = Alertable;
|
CurrentThread->Alertable = Alertable;
|
||||||
CurrentThread->WaitMode = WaitMode;
|
CurrentThread->WaitMode = WaitMode;
|
||||||
CurrentThread->WaitReason = WaitReason;
|
CurrentThread->WaitReason = WaitReason;
|
||||||
CurrentThread->WaitTime = 0;
|
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
|
||||||
CurrentThread->State = Waiting;
|
CurrentThread->State = Waiting;
|
||||||
|
|
||||||
/* Find a new thread to run */
|
/* Find a new thread to run */
|
||||||
|
@ -610,13 +601,9 @@ KeWaitForMultipleObjects(ULONG Count,
|
||||||
WaitBlock->NextWaitBlock = TimerWaitBlock;
|
WaitBlock->NextWaitBlock = TimerWaitBlock;
|
||||||
|
|
||||||
/* Set up the Timer Wait Block */
|
/* Set up the Timer Wait Block */
|
||||||
TimerWaitBlock->Object = (PVOID)ThreadTimer;
|
|
||||||
TimerWaitBlock->Thread = CurrentThread;
|
|
||||||
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
|
|
||||||
TimerWaitBlock->WaitType = WaitAny;
|
|
||||||
TimerWaitBlock->NextWaitBlock = WaitBlockArray;
|
TimerWaitBlock->NextWaitBlock = WaitBlockArray;
|
||||||
|
|
||||||
/* Link the timer to this Wait Block */
|
/* Initialize the list head */
|
||||||
InitializeListHead(&ThreadTimer->Header.WaitListHead);
|
InitializeListHead(&ThreadTimer->Header.WaitListHead);
|
||||||
|
|
||||||
/* Insert the Timer into the Timer Lists and enable it */
|
/* Insert the Timer into the Timer Lists and enable it */
|
||||||
|
@ -655,7 +642,7 @@ KeWaitForMultipleObjects(ULONG Count,
|
||||||
CurrentThread->Alertable = Alertable;
|
CurrentThread->Alertable = Alertable;
|
||||||
CurrentThread->WaitMode = WaitMode;
|
CurrentThread->WaitMode = WaitMode;
|
||||||
CurrentThread->WaitReason = WaitReason;
|
CurrentThread->WaitReason = WaitReason;
|
||||||
CurrentThread->WaitTime = 0;
|
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
|
||||||
CurrentThread->State = Waiting;
|
CurrentThread->State = Waiting;
|
||||||
|
|
||||||
/* Find a new thread to run */
|
/* Find a new thread to run */
|
||||||
|
|
Loading…
Reference in a new issue