diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-11 13:43:44 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-11 13:43:44 +0000 |
commit | 99b0796eb6cd0bcc7d7facdd1a1a6834cca588dd (patch) | |
tree | cda401c44fc86b6eeb73cab594d682150e5b5c94 /plugins/BasicHistory/src | |
parent | f01a47f097c67d7636cda151e0681a4eb538aa32 (diff) |
various mir_forkthread quirks
git-svn-id: http://svn.miranda-ng.org/main/trunk@3975 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/BasicHistory/src')
-rw-r--r-- | plugins/BasicHistory/src/Scheduler.cpp | 39 |
1 files changed, 17 insertions, 22 deletions
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)
|