Add functions to transition threads to deferred ready or transition states
This commit is contained in:
@@ -22,6 +22,7 @@ namespace KE
|
||||
|
||||
public:
|
||||
STATIC XTAPI VOID AttachThread(IN PKTHREAD Thread);
|
||||
STATIC XTAPI VOID DispatchReadyThread(IN PKTHREAD Thread);
|
||||
STATIC XTAPI PETHREAD GetInitialThread(VOID);
|
||||
STATIC XTAPI XTSTATUS InitializeIdleThread(IN PKPROCESS IdleProcess,
|
||||
IN OUT PKTHREAD IdleThread,
|
||||
@@ -36,6 +37,7 @@ namespace KE
|
||||
IN PVOID EnvironmentBlock,
|
||||
IN PVOID Stack,
|
||||
IN BOOLEAN AttachToProcess);
|
||||
STATIC XTAPI VOID ReadyThread(IN PKTHREAD Thread);
|
||||
|
||||
private:
|
||||
STATIC XTAPI VOID HandleSystemThreadExit(VOID);
|
||||
|
||||
@@ -75,6 +75,44 @@ KE::KThread::AttachThread(IN OUT PKTHREAD Thread)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transitions a thread to the ready state and queues it for execution within the dispatcher database.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread to be dispatched.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KE::KThread::DispatchReadyThread(IN PKTHREAD Thread)
|
||||
{
|
||||
PKPROCESS Process;
|
||||
|
||||
/* Extract the process from the thread's APC state */
|
||||
Process = Thread->ApcState.Process;
|
||||
|
||||
/* Verify if the process and thread are resident in physical memory */
|
||||
if(Process->State != ProcessInMemory)
|
||||
{
|
||||
/* Process is swapped out, place the thread in a transition state */
|
||||
Thread->State = Transition;
|
||||
}
|
||||
else if(!Thread->KernelStackResident)
|
||||
{
|
||||
/* Increment the active stack count and transition the thread */
|
||||
Process->StackCount++;
|
||||
Thread->State = Transition;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Both process and thread's stack are fully resident, queue the thread for execution */
|
||||
KE::Scheduler::InsertDeferredReadyList(Thread);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a pointer to the system's initial executive thread object.
|
||||
*
|
||||
@@ -346,6 +384,28 @@ KE::KThread::InitializeThread(IN PKPROCESS Process,
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a thread for execution by safely acquiring the dispatcher database lock.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread to be readied.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KE::KThread::ReadyThread(IN PKTHREAD Thread)
|
||||
{
|
||||
/* Raise runlevel to SYNC level and acquire the dispatcher database lock */
|
||||
KE::RaiseRunLevel RunLevel(SYNC_LEVEL);
|
||||
KE::QueuedSpinLockGuard DispatcherGuard(DispatcherLock);
|
||||
|
||||
/* Evaluate residency and queue the thread */
|
||||
DispatchReadyThread(Thread);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend APC-built thread NOP routine. It takes no actions.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user