From 99b0796eb6cd0bcc7d7facdd1a1a6834cca588dd Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 11 Mar 2013 13:43:44 +0000 Subject: various mir_forkthread quirks git-svn-id: http://svn.miranda-ng.org/main/trunk@3975 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/BasicHistory/src/Scheduler.cpp | 39 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'plugins/BasicHistory/src') diff --git a/plugins/BasicHistory/src/Scheduler.cpp b/plugins/BasicHistory/src/Scheduler.cpp index 3b2ba18ab9..a317a7dac4 100644 --- a/plugins/BasicHistory/src/Scheduler.cpp +++ b/plugins/BasicHistory/src/Scheduler.cpp @@ -40,8 +40,8 @@ time_t GetNextExportTime(TaskOptions& to); void SchedulerThreadFunc(void*); volatile bool finishThread = false; bool initTask = false; -HANDLE thread = NULL; -HANDLE threadEvent; +HANDLE hThread = NULL; +HANDLE hThreadEvent; time_t nextExportTime; void StartThread(bool init); void StopThread(); @@ -856,24 +856,21 @@ void SchedulerThreadFunc(void*) { if(initTask) { - WaitForSingleObject(threadEvent, 5 * 1000); + WaitForSingleObject(hThreadEvent, 5 * 1000); initTask = false; } - while(!finishThread) - { + while(!finishThread) { DWORD timeWait; time_t now = time(NULL); while(nextExportTime <= now) - { if(!ExecuteCurrentTask(now)) return; - } time_t dif = nextExportTime - now; timeWait = (dif > 60 * 60 * 24) ? (60 * 60 * 1000) : (60 * 1000); - WaitForSingleObject(threadEvent, timeWait); + WaitForSingleObject(hThreadEvent, timeWait); } } @@ -883,26 +880,24 @@ void StartThread(bool init) initTask = false; bool isExport = GetNextExportTime(init, time(NULL)); - if(isExport) - { + if(isExport) { finishThread = false; - threadEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - thread = mir_forkthread(SchedulerThreadFunc, NULL); + hThreadEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + hThread = mir_forkthread(SchedulerThreadFunc, NULL); } } void StopThread() { - if(thread != NULL) - { - finishThread = true; - SetEvent(threadEvent); - WaitForSingleObject(thread, INFINITE); - //CloseHandle(thread); - CloseHandle(threadEvent); - thread = NULL; - threadEvent = NULL; - } + if(hThread == NULL) + return; + + finishThread = true; + SetEvent(hThreadEvent); + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThreadEvent); + hThread = NULL; + hThreadEvent = NULL; } bool GetNextExportTime(bool init, time_t now) -- cgit v1.2.3