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
,
67 extern unsigned int init_stack
;
69 Thread
= ExAllocatePool(NonPagedPool
, sizeof(ETHREAD
));
70 RtlZeroMemory(Thread
, sizeof(ETHREAD
));
71 Thread
->ThreadsProcess
= Process
;
74 KernelStack
= (PVOID
)init_stack
;
78 KernelStack
= MmCreateKernelStack(FALSE
);
80 KeInitializeThread(&Process
->Pcb
,
82 PspSystemThreadStartup
,
88 Thread
->Tcb
.ApcQueueable
= TRUE
;
89 InitializeListHead(&Thread
->IrpList
);
91 return STATUS_SUCCESS
;
96 * Antique vestigial code left alive for the sole purpose of First/Idle Thread
97 * creation until I can merge my fix for properly creating them.
102 PsInitIdleThread(VOID
)
107 PsInitializeIdleOrFirstThread(PsIdleProcess
,
113 oldIrql
= KeAcquireDispatcherDatabaseLock ();
114 KiUnblockThread(&IdleThread
->Tcb
, NULL
, 0);
115 KeReleaseDispatcherDatabaseLock(oldIrql
);
117 KeGetCurrentPrcb()->IdleThread
= &IdleThread
->Tcb
;
118 KeSetPriorityThread(&IdleThread
->Tcb
, LOW_PRIORITY
);
119 KeSetAffinityThread(&IdleThread
->Tcb
, 1 << 0);