Author: ekohl Date: Sat Apr 15 10:33:29 2017 New Revision: 74317
URL: http://svn.reactos.org/svn/reactos?rev=74317&view=rev Log: [SCHEDSVC] Insert a job into the start list when it is loaded or added. Remove it from the start list when it gets deleted. The start list is sorted by start time.
Modified: trunk/reactos/base/services/schedsvc/job.c trunk/reactos/base/services/schedsvc/precomp.h trunk/reactos/base/services/schedsvc/rpcserver.c
Modified: trunk/reactos/base/services/schedsvc/job.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/schedsvc/job.... ============================================================================== --- trunk/reactos/base/services/schedsvc/job.c [iso-8859-1] (original) +++ trunk/reactos/base/services/schedsvc/job.c [iso-8859-1] Sat Apr 15 10:33:29 2017 @@ -276,18 +276,24 @@ pJob->JobId = dwNextJobId++; dwJobCount++;
+ // Cancel the start timer + /* Append the new job to the job list */ InsertTailList(&JobListHead, &pJob->JobEntry);
+ /* Calculate the next start time */ + CalculateNextStartTime(pJob); + + /* Insert the job into the start list */ + InsertJobIntoStartList(&StartListHead, pJob); +#if 0 + DumpStartList(&StartListHead); +#endif + + // Update the start timer + /* Release the job list lock */ RtlReleaseResource(&JobListLock); - - /* Calculate the next start time */ - CalculateNextStartTime(pJob); - - // Insert job into the start list - - // Update the start timer
pJob = NULL; } @@ -330,7 +336,10 @@ CalculateNextStartTime(PJOB pJob) { SYSTEMTIME StartTime; + FILETIME FileTime; DWORD_PTR Now; + + TRACE("CalculateNextStartTime(%p)\n", pJob);
GetLocalTime(&StartTime);
@@ -365,8 +374,82 @@ } }
- ERR("Next start: %02hu:%02hu %02hu.%02hu.%hu\n", StartTime.wHour, - StartTime.wMinute, StartTime.wDay, StartTime.wMonth, StartTime.wYear); - - SystemTimeToFileTime(&StartTime, &pJob->StartTime); -} + TRACE("Next start: %02hu:%02hu %02hu.%02hu.%hu\n", StartTime.wHour, + StartTime.wMinute, StartTime.wDay, StartTime.wMonth, StartTime.wYear); + + SystemTimeToFileTime(&StartTime, &FileTime); + pJob->StartTime.u.LowPart = FileTime.dwLowDateTime; + pJob->StartTime.u.HighPart = FileTime.dwHighDateTime; +} + + +VOID +InsertJobIntoStartList( + _In_ PLIST_ENTRY StartListHead, + _In_ PJOB pJob) +{ + PLIST_ENTRY CurrentEntry, PreviousEntry; + PJOB CurrentJob; + + if (IsListEmpty(StartListHead)) + { + InsertHeadList(StartListHead, &pJob->StartEntry); + return; + } + + CurrentEntry = StartListHead->Flink; + while (CurrentEntry != StartListHead) + { + CurrentJob = CONTAINING_RECORD(CurrentEntry, JOB, StartEntry); + + if ((CurrentEntry == StartListHead->Flink) && + (pJob->StartTime.QuadPart < CurrentJob->StartTime.QuadPart)) + { + /* Insert before the first entry */ + InsertHeadList(StartListHead, &pJob->StartEntry); + return; + } + + if (pJob->StartTime.QuadPart < CurrentJob->StartTime.QuadPart) + { + /* Insert between the previous and the current entry */ + PreviousEntry = CurrentEntry->Blink; + pJob->StartEntry.Blink = PreviousEntry; + pJob->StartEntry.Flink = CurrentEntry; + PreviousEntry->Flink = &pJob->StartEntry; + CurrentEntry->Blink = &pJob->StartEntry; + return; + } + + if ((CurrentEntry->Flink == StartListHead) && + (pJob->StartTime.QuadPart >= CurrentJob->StartTime.QuadPart)) + { + /* Insert after the last entry */ + InsertTailList(StartListHead, &pJob->StartEntry); + return; + } + + CurrentEntry = CurrentEntry->Flink; + } +} + + +VOID +DumpStartList( + _In_ PLIST_ENTRY StartListHead) +{ + PLIST_ENTRY CurrentEntry; + PJOB CurrentJob; + + CurrentEntry = StartListHead->Flink; + while (CurrentEntry != StartListHead) + { + CurrentJob = CONTAINING_RECORD(CurrentEntry, JOB, StartEntry); + + TRACE("%3lu: %016I64x\n", CurrentJob->JobId, CurrentJob->StartTime.QuadPart); + + CurrentEntry = CurrentEntry->Flink; + } +} + +/* EOF */
Modified: trunk/reactos/base/services/schedsvc/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/schedsvc/prec... ============================================================================== --- trunk/reactos/base/services/schedsvc/precomp.h [iso-8859-1] (original) +++ trunk/reactos/base/services/schedsvc/precomp.h [iso-8859-1] Sat Apr 15 10:33:29 2017 @@ -4,6 +4,7 @@ #define WIN32_NO_STATUS #define _INC_WINDOWS #define COM_NO_WINDOWS_H +#include <limits.h> #include <stdarg.h> #include <stdio.h> #include <windef.h> @@ -28,7 +29,7 @@ LIST_ENTRY JobEntry;
LIST_ENTRY StartEntry; - FILETIME StartTime; + ULARGE_INTEGER StartTime; WCHAR Name[9];
DWORD JobId; @@ -39,7 +40,6 @@ WCHAR Command[1]; } JOB, *PJOB;
-#define DWORD_MAX 0xffffffffUL
extern DWORD dwNextJobId; extern DWORD dwJobCount; @@ -66,7 +66,17 @@
VOID CalculateNextStartTime( - PJOB pJob); + _In_ PJOB pJob); + +VOID +InsertJobIntoStartList( + _In_ PLIST_ENTRY StartListHead, + _In_ PJOB pJob); + +VOID +DumpStartList( + _In_ PLIST_ENTRY StartListHead); +
/* rpcserver.c */
Modified: trunk/reactos/base/services/schedsvc/rpcserver.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/schedsvc/rpcs... ============================================================================== --- trunk/reactos/base/services/schedsvc/rpcserver.c [iso-8859-1] (original) +++ trunk/reactos/base/services/schedsvc/rpcserver.c [iso-8859-1] Sat Apr 15 10:33:29 2017 @@ -112,21 +112,27 @@ pJob->JobId = dwNextJobId++; dwJobCount++;
+ // Cancel the start timer + /* Append the new job to the job list */ InsertTailList(&JobListHead, &pJob->JobEntry);
+ /* Save the job in the registry */ + SaveJob(pJob); + + /* Calculate the next start time */ + CalculateNextStartTime(pJob); + + /* Insert the job into the start list */ + InsertJobIntoStartList(&StartListHead, pJob); +#if 0 + DumpStartList(&StartListHead); +#endif + + // Update the start timer + /* Release the job list lock */ RtlReleaseResource(&JobListLock); - - /* Save the job in the registry */ - SaveJob(pJob); - - /* Calculate the next start time */ - CalculateNextStartTime(pJob); - - // Insert job into the start list - - // Update the start timer
/* Return the new job ID */ *pJobId = pJob->JobId; @@ -156,6 +162,8 @@ /* Acquire the job list lock exclusively */ RtlAcquireResourceExclusive(&JobListLock, TRUE);
+ // Cancel the start timer + JobEntry = JobListHead.Flink; while (JobEntry != &JobListHead) { @@ -163,9 +171,11 @@
if ((CurrentJob->JobId >= MinJobId) && (CurrentJob->JobId <= MaxJobId)) { - // Remove job from the start list - - // Update the start timer + /* Remove the job from the start list */ + RemoveEntryList(&CurrentJob->StartEntry); +#if 0 + DumpStartList(&StartListHead); +#endif
/* Remove the job from the registry */ DeleteJob(CurrentJob); @@ -183,6 +193,8 @@ JobEntry = JobEntry->Flink; }
+ // Update the start timer + /* Release the job list lock */ RtlReleaseResource(&JobListLock);
@@ -245,7 +257,7 @@ (wcslen(CurrentJob->Command) + 1) * sizeof(WCHAR); TRACE("dwEntrySize: %lu\n", dwEntrySize);
- if ((PreferedMaximumLength != DWORD_MAX) && + if ((PreferedMaximumLength != ULONG_MAX) && (dwRequiredSize + dwEntrySize > PreferedMaximumLength)) break;
@@ -259,7 +271,7 @@ TRACE("dwEntriesToRead: %lu\n", dwEntriesToRead); TRACE("dwRequiredSize: %lu\n", dwRequiredSize);
- if (PreferedMaximumLength != DWORD_MAX) + if (PreferedMaximumLength != ULONG_MAX) dwRequiredSize = PreferedMaximumLength;
TRACE("Allocating dwRequiredSize: %lu\n", dwRequiredSize);