Refactor thread ready state transitions into Scheduler class
All checks were successful
Builds / ExectOS (amd64, debug) (push) Successful in 25s
Builds / ExectOS (amd64, release) (push) Successful in 41s
Builds / ExectOS (i686, debug) (push) Successful in 39s
Builds / ExectOS (i686, release) (push) Successful in 29s

This commit is contained in:
2026-06-17 20:56:05 +02:00
parent 854a8c8eef
commit 156ae3efab
4 changed files with 62 additions and 62 deletions

View File

@@ -22,7 +22,6 @@ 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,
@@ -37,7 +36,6 @@ namespace KE
IN PVOID EnvironmentBlock,
IN PVOID Stack,
IN BOOLEAN AttachToProcess);
STATIC XTAPI VOID ReadyThread(IN PKTHREAD Thread);
private:
STATIC XTAPI VOID HandleSystemThreadExit(VOID);

View File

@@ -19,6 +19,8 @@ namespace KE
{
public:
STATIC XTFASTCALL VOID InsertDeferredReadyList(IN PKTHREAD Thread);
STATIC XTAPI VOID ProcessReadyThread(IN PKTHREAD Thread);
STATIC XTAPI VOID ReadyThread(IN PKTHREAD Thread);
};
}

View File

@@ -75,44 +75,6 @@ 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.
*
@@ -385,28 +347,6 @@ 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.
*

View File

@@ -35,3 +35,63 @@ KE::Scheduler::InsertDeferredReadyList(IN PKTHREAD Thread)
/* Insert the thread into the deferred ready list */
RTL::LifoQueue::PushEntryList(&Prcb->DeferredReadyListHead, &Thread->SwapListEntry);
}
/**
* 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::Scheduler::ProcessReadyThread(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 */
InsertDeferredReadyList(Thread);
}
}
/**
* 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::Scheduler::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 */
ProcessReadyThread(Thread);
}