Sync with trunk head (part 1 or 2)
[reactos.git] / ntoskrnl / mm / mpw.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/mm/mpw.c
5 * PURPOSE: Writes data that has been modified in memory but not on
6 * the disk
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES ****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <debug.h>
16
17 /* GLOBALS *******************************************************************/
18
19 HANDLE MpwThreadHandle;
20 static CLIENT_ID MpwThreadId;
21 KEVENT MpwThreadEvent;
22 BOOLEAN MpwThreadShouldTerminate;
23
24 /* FUNCTIONS *****************************************************************/
25
26 NTSTATUS NTAPI
27 MmMpwThreadMain(PVOID Ignored)
28 {
29 NTSTATUS Status;
30 ULONG PagesWritten;
31 LARGE_INTEGER Timeout;
32
33 Timeout.QuadPart = -50000000;
34
35 for(;;)
36 {
37 Status = KeWaitForSingleObject(&MpwThreadEvent,
38 0,
39 KernelMode,
40 FALSE,
41 &Timeout);
42 if (!NT_SUCCESS(Status))
43 {
44 DbgPrint("MpwThread: Wait failed\n");
45 KeBugCheck(MEMORY_MANAGEMENT);
46 return(STATUS_UNSUCCESSFUL);
47 }
48 if (MpwThreadShouldTerminate)
49 {
50 DbgPrint("MpwThread: Terminating\n");
51 return(STATUS_SUCCESS);
52 }
53
54 PagesWritten = 0;
55
56 CcRosFlushDirtyPages(128, &PagesWritten);
57 }
58 }
59
60 NTSTATUS
61 NTAPI
62 MmInitMpwThread(VOID)
63 {
64 KPRIORITY Priority;
65 NTSTATUS Status;
66
67 MpwThreadShouldTerminate = FALSE;
68 KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
69
70 Status = PsCreateSystemThread(&MpwThreadHandle,
71 THREAD_ALL_ACCESS,
72 NULL,
73 NULL,
74 &MpwThreadId,
75 (PKSTART_ROUTINE) MmMpwThreadMain,
76 NULL);
77 if (!NT_SUCCESS(Status))
78 {
79 return(Status);
80 }
81
82 Priority = 1;
83 NtSetInformationThread(MpwThreadHandle,
84 ThreadPriority,
85 &Priority,
86 sizeof(Priority));
87
88 return(STATUS_SUCCESS);
89 }
90
91 NTSTATUS
92 NTAPI
93 MmInitBsmThread(VOID)
94 {
95 NTSTATUS Status;
96 OBJECT_ATTRIBUTES ObjectAttributes;
97 HANDLE ThreadHandle;
98
99 /* Create the thread */
100 InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
101 Status = PsCreateSystemThread(&ThreadHandle,
102 THREAD_ALL_ACCESS,
103 &ObjectAttributes,
104 NULL,
105 NULL,
106 KeBalanceSetManager,
107 NULL);
108
109 /* Close the handle and return status */
110 ZwClose(ThreadHandle);
111 return Status;
112 }