| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: timer.c 1335 2008-12-12 23:49:02Z stevenhl $ | 
|---|
| 5 |  | 
|---|
| 6 | Timer thread | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2006, 2008 Steven H. Levine | 
|---|
| 10 |  | 
|---|
| 11 | 22 Jul 06 SHL Check more run time errors | 
|---|
| 12 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| 13 | 10 Dec 08 SHL Integrate exception handler support | 
|---|
| 14 |  | 
|---|
| 15 | ***********************************************************************/ | 
|---|
| 16 |  | 
|---|
| 17 | // #include <process.h>                 // _beginthread | 
|---|
| 18 |  | 
|---|
| 19 | #define INCL_DOS | 
|---|
| 20 | #define INCL_DOSERRORS | 
|---|
| 21 | #define INCL_WIN | 
|---|
| 22 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| 23 |  | 
|---|
| 24 | #include "fm3dll.h" | 
|---|
| 25 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
| 26 | #include "mainwnd.h"                    // Data declaration(s) | 
|---|
| 27 | #include "datamin.h"                    // Data declaration(s) | 
|---|
| 28 | #include "fm3str.h" | 
|---|
| 29 | #include "errutil.h"                    // Dos_Error... | 
|---|
| 30 | #include "strutil.h"                    // GetPString | 
|---|
| 31 | #include "timer.h" | 
|---|
| 32 | #include "misc.h"                       // PostMsg | 
|---|
| 33 | #include "excputil.h"                   // xbeginthread | 
|---|
| 34 |  | 
|---|
| 35 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 36 |  | 
|---|
| 37 | static HEV hevTimerSem; | 
|---|
| 38 |  | 
|---|
| 39 | static void TimerThread(void *args) | 
|---|
| 40 | { | 
|---|
| 41 | HAB hab2; | 
|---|
| 42 | HMQ hmq2; | 
|---|
| 43 | ULONG cntr = 0; | 
|---|
| 44 |  | 
|---|
| 45 | priority_bumped(); | 
|---|
| 46 | hab2 = WinInitialize(0); | 
|---|
| 47 | if (hab2) { | 
|---|
| 48 | hmq2 = WinCreateMsgQueue(hab2, 0); | 
|---|
| 49 | if (hmq2) { | 
|---|
| 50 | WinCancelShutdown(hmq2, TRUE); | 
|---|
| 51 | if (!DosCreateEventSem(NULL, &hevTimerSem, 0, FALSE)) { | 
|---|
| 52 | for (;;) { | 
|---|
| 53 | if (DosWaitEventSem(hevTimerSem, 3000) != ERROR_TIMEOUT) | 
|---|
| 54 | break; | 
|---|
| 55 | cntr++; | 
|---|
| 56 | if (hwndTree && !(cntr % 3)) | 
|---|
| 57 | PostMsg(hwndTree, UM_TIMER, MPVOID, MPVOID); | 
|---|
| 58 | if (hwndBubble && WinIsWindowVisible(hwndBubble)) | 
|---|
| 59 | PostMsg(hwndBubble, UM_TIMER, MPVOID, MPVOID); | 
|---|
| 60 | if (DataHwnd) | 
|---|
| 61 | PostMsg(DataHwnd, UM_TIMER, MPVOID, MPVOID); | 
|---|
| 62 | } | 
|---|
| 63 | DosCloseEventSem(hevTimerSem); | 
|---|
| 64 | } | 
|---|
| 65 | WinDestroyMsgQueue(hmq2); | 
|---|
| 66 | } | 
|---|
| 67 | WinTerminate(hab2); | 
|---|
| 68 | } | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | //== StartTimer() return TRUE can start thread == | 
|---|
| 72 |  | 
|---|
| 73 | BOOL StartTimer(void) | 
|---|
| 74 | { | 
|---|
| 75 | INT rc = xbeginthread(TimerThread, | 
|---|
| 76 | 32768, | 
|---|
| 77 | (PVOID)0, | 
|---|
| 78 | pszSrcFile, | 
|---|
| 79 | __LINE__); | 
|---|
| 80 |  | 
|---|
| 81 | return rc != -1; | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | void StopTimer(void) | 
|---|
| 85 | { | 
|---|
| 86 | DosPostEventSem(hevTimerSem); | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | #pragma alloc_text(TIMER,TimerThread,StartTimer,StopTimer) | 
|---|