2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ps/idle.c
5 * PURPOSE: Using idle time
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8 * David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 #if defined (ALLOC_PRAGMA)
18 #pragma alloc_text(INIT, PsInitIdleThread)
21 /* GLOBALS *******************************************************************/
23 extern PEPROCESS PsIdleProcess
;
25 /* FUNCTIONS *****************************************************************/
27 /** System idle thread procedure
31 PsIdleThreadMain(PVOID Context
)
35 PKPRCB Prcb
= KeGetCurrentPrcb();
39 if (Prcb
->DpcData
[0].DpcQueueDepth
> 0)
41 KeRaiseIrql(DISPATCH_LEVEL
,&oldlvl
);
42 KiDispatchInterrupt();
54 * Antique vestigial code left alive for the sole purpose of First/Idle Thread
55 * creation until I can merge my fix for properly creating them.
59 PsInitializeIdleOrFirstThread(PEPROCESS Process
,
61 PKSTART_ROUTINE StartRoutine
,
62 KPROCESSOR_MODE AccessMode
,
66 ULONG_PTR KernelStack
;
67 extern unsigned int init_stack_top
;
69 Thread
= ExAllocatePool(NonPagedPool
, sizeof(ETHREAD
));
70 RtlZeroMemory(Thread
, sizeof(ETHREAD
));
71 Thread
->ThreadsProcess
= Process
;
74 KernelStack
= init_stack_top
;
78 KernelStack
= (ULONG_PTR
)MmCreateKernelStack(FALSE
) + KERNEL_STACK_SIZE
;
80 KeInitializeThread(&Process
->Pcb
,
82 PspSystemThreadStartup
,
88 InitializeListHead(&Thread
->IrpList
);
90 return STATUS_SUCCESS
;
95 * Antique vestigial code left alive for the sole purpose of First/Idle Thread
96 * creation until I can merge my fix for properly creating them.
101 PsInitIdleThread(VOID
)
106 PsInitializeIdleOrFirstThread(PsIdleProcess
,
112 oldIrql
= KeAcquireDispatcherDatabaseLock ();
113 KiUnblockThread(&IdleThread
->Tcb
, NULL
, 0);
114 KeReleaseDispatcherDatabaseLock(oldIrql
);
116 KeGetCurrentPrcb()->IdleThread
= &IdleThread
->Tcb
;
117 KeSetPriorityThread(&IdleThread
->Tcb
, LOW_PRIORITY
);
118 KeSetAffinityThread(&IdleThread
->Tcb
, 1 << 0);