:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / ps / idle.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS kernel
4  * FILE:            ntoskrnl/ps/idle.c
5  * PURPOSE:         Using idle time
6  * PROGRAMMER:      David Welch (welch@cwcom.net)
7  * UPDATE HISTORY:
8  *                  Created 22/05/98
9  */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <internal/ke.h>
15 #include <internal/ps.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20 /* GLOBALS *******************************************************************/
21
22 HANDLE PsIdleThreadHandle = NULL;
23 extern ULONG DpcQueueSize;
24 PETHREAD PiIdleThread;
25
26 /* FUNCTIONS *****************************************************************/
27
28 NTSTATUS STDCALL
29 PsIdleThreadMain(PVOID Context)
30 {
31    KIRQL oldlvl;
32    
33    for(;;)
34      {
35        if (DpcQueueSize > 0)
36          {
37            KeRaiseIrql(DISPATCH_LEVEL,&oldlvl);
38            KiDispatchInterrupt();
39            KeLowerIrql(oldlvl);
40          }
41        NtYieldExecution();
42        __asm__( "hlt" );
43      }
44 }
45
46 VOID PsInitIdleThread(VOID)
47 {
48    KPRIORITY Priority;
49    ULONG Affinity;
50
51    PsCreateSystemThread(&PsIdleThreadHandle,
52                         THREAD_ALL_ACCESS,
53                         NULL,
54                         NULL,
55                         NULL,
56                         PsIdleThreadMain,
57                         NULL);
58    
59    Priority = LOW_PRIORITY;
60    NtSetInformationThread(PsIdleThreadHandle,
61                           ThreadPriority,
62                           &Priority,
63                           sizeof(Priority));
64    Affinity = 1 << 0;
65    NtSetInformationThread(PsIdleThreadHandle,
66                           ThreadAffinityMask,
67                           &Affinity,
68                           sizeof(Affinity));
69 }