Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

yield.c File Reference

#include "ki.h"

Go to the source code of this file.

Functions

NTSTATUS NtYieldExecution (VOID)


Function Documentation

NTSTATUS NtYieldExecution VOID   ) 
 

Definition at line 29 of file yield.c.

References _KTHREAD::ApcState, _KTHREAD::BasePriority, KeGetCurrentPrcb, KeGetCurrentThread, KiDispatcherReadyListHead, KiFindReadyThread(), KiLockDispatcherDatabase, KiReadySummary, KiSwapThread(), KiUnlockDispatcherDatabase(), _KTHREAD::NextProcessor, NTSTATUS(), NULL, _KTHREAD::Priority, _KTHREAD::PriorityDecrement, _KAPC_STATE::Process, _KTHREAD::Quantum, Ready, SetMember, _KTHREAD::State, Status, _KPROCESS::ThreadQuantum, _KTHREAD::WaitIrql, and _KTHREAD::WaitListEntry.

Referenced by PeekMessage(), and ReadConsoleInternal().

00035 : 00036 00037 This function yields execution to any ready thread for up to one 00038 quantum. 00039 00040 Arguments: 00041 00042 None. 00043 00044 Return Value: 00045 00046 None. 00047 00048 --*/ 00049 00050 { 00051 00052 KIRQL OldIrql; 00053 PRKPRCB Prcb; 00054 KPRIORITY Priority; 00055 NTSTATUS Status; 00056 PRKTHREAD Thread; 00057 00058 // 00059 // If any other threads are ready, then attempt to yield execution. 00060 // 00061 00062 Status = STATUS_NO_YIELD_PERFORMED; 00063 if (KiReadySummary != 0) { 00064 00065 // 00066 // If a thread has not already been selected for execution, then 00067 // attempt to select another thread for execution. 00068 // 00069 00070 Thread = KeGetCurrentThread(); 00071 KiLockDispatcherDatabase(&Thread->WaitIrql); 00072 Prcb = KeGetCurrentPrcb(); 00073 if (Prcb->NextThread == NULL) { 00074 Prcb->NextThread = KiFindReadyThread(Thread->NextProcessor, 1); 00075 } 00076 00077 // 00078 // If a new thread has been selected for execution, then switch 00079 // immediately to the selected thread. 00080 // 00081 00082 if (Prcb->NextThread != NULL) { 00083 00084 // 00085 // Give the current thread a new quantum, simulate a quantum 00086 // end, insert the current thread in the appropriate ready list, 00087 // and switch context to selected thread. 00088 // 00089 00090 Thread->Quantum = Thread->ApcState.Process->ThreadQuantum; 00091 Thread->State = Ready; 00092 Priority = Thread->Priority; 00093 if (Priority < LOW_REALTIME_PRIORITY) { 00094 Priority = Priority - Thread->PriorityDecrement - 1; 00095 if (Priority < Thread->BasePriority) { 00096 Priority = Thread->BasePriority; 00097 } 00098 00099 Thread->PriorityDecrement = 0; 00100 00101 } 00102 00103 Thread->Priority = (SCHAR)Priority; 00104 00105 InsertTailList(&KiDispatcherReadyListHead[Priority], 00106 &Thread->WaitListEntry); 00107 00108 SetMember(Priority, KiReadySummary); 00109 KiSwapThread(); 00110 Status = STATUS_SUCCESS; 00111 00112 } else { 00113 KiUnlockDispatcherDatabase(Thread->WaitIrql); 00114 } 00115 } 00116 00117 return Status; 00118 } }


Generated on Sat May 15 19:46:11 2004 for test by doxygen 1.3.7