https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4735cc2ab5301b9e49847…
commit 4735cc2ab5301b9e4984738ff52d1e23911589a3
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Apr 12 13:11:33 2020 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Apr 12 13:12:23 2020 +0200
[TIMEDATE] Pervent running multiple NTP updates at once
- Run the NTP uptate from a separate thread
- Do not accept another update until the current one has finished
CORE-16835
---
dll/cpl/timedate/internettime.c | 46 +++++++++++++++++++++++++++++++++--------
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/dll/cpl/timedate/internettime.c b/dll/cpl/timedate/internettime.c
index 7e85fa1ffce..001c25d9949 100644
--- a/dll/cpl/timedate/internettime.c
+++ b/dll/cpl/timedate/internettime.c
@@ -304,6 +304,7 @@ OnInitDialog(HWND hwnd)
EnableDialogText(hwnd);
CreateNTPServerList(hwnd);
SyncNTPStatusInit(hwnd);
+ SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)FALSE);
}
static VOID
@@ -341,6 +342,40 @@ OnAutoSync(BOOL Sync)
RegCloseKey(hKey);
}
+static DWORD
+UpdateThread(
+ _In_ LPVOID lpParameter)
+{
+ HWND hwndDlg;
+ DWORD dwError;
+
+ hwndDlg = (HWND)lpParameter;
+
+ SetNTPServer(hwndDlg, TRUE);
+
+ dwError = W32TimeSyncNow(L"localhost", 0, 0);
+ UpdateNTPStatus(hwndDlg, dwError);
+
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)FALSE);
+ return 0;
+}
+
+static VOID
+OnUpdate(
+ HWND hwndDlg)
+{
+ if ((BOOL)GetWindowLongPtr(hwndDlg, DWLP_USER) == FALSE)
+ {
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)TRUE);
+
+ if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)UpdateThread, (PVOID)hwndDlg,
0, NULL) == NULL)
+ {
+ UpdateNTPStatus(hwndDlg, GetLastError());
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)FALSE);
+ }
+ }
+}
+
/* Property page dialog callback */
INT_PTR CALLBACK
InetTimePageProc(HWND hwndDlg,
@@ -358,15 +393,8 @@ InetTimePageProc(HWND hwndDlg,
switch(LOWORD(wParam))
{
case IDC_UPDATEBUTTON:
- {
- DWORD dwError;
-
- SetNTPServer(hwndDlg, TRUE);
-
- dwError = W32TimeSyncNow(L"localhost", 0, 0);
- UpdateNTPStatus(hwndDlg, dwError);
- }
- break;
+ OnUpdate(hwndDlg);
+ break;
case IDC_SERVERLIST:
if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) ==
CBN_EDITCHANGE))