| [329] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: timer.c 689 2007-06-15 06:33:24Z stevenhl $ | 
|---|
|  | 5 |  | 
|---|
|  | 6 | Timer thread | 
|---|
|  | 7 |  | 
|---|
|  | 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
|  | 9 | Copyright (c) 2006 Steven H. Levine | 
|---|
|  | 10 |  | 
|---|
|  | 11 | 22 Jul 06 SHL Check more run time errors | 
|---|
|  | 12 |  | 
|---|
|  | 13 | ***********************************************************************/ | 
|---|
|  | 14 |  | 
|---|
| [2] | 15 | #define INCL_DOS | 
|---|
|  | 16 | #define INCL_DOSERRORS | 
|---|
|  | 17 | #define INCL_WIN | 
|---|
| [329] | 18 | #include <os2.h> | 
|---|
| [2] | 19 |  | 
|---|
|  | 20 | #include <stdarg.h> | 
|---|
|  | 21 | #include <stdio.h> | 
|---|
|  | 22 | #include <stdlib.h> | 
|---|
|  | 23 | #include <string.h> | 
|---|
| [689] | 24 | #include <process.h>                    // _beginthread | 
|---|
| [329] | 25 |  | 
|---|
| [2] | 26 | #include "fm3dll.h" | 
|---|
|  | 27 | #include "fm3str.h" | 
|---|
|  | 28 |  | 
|---|
|  | 29 | #pragma alloc_text(TIMER,TimerThread,StartTimer,StopTimer) | 
|---|
|  | 30 |  | 
|---|
| [329] | 31 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 32 |  | 
|---|
| [2] | 33 | static HEV hevTimerSem; | 
|---|
|  | 34 |  | 
|---|
| [551] | 35 | static void TimerThread(void *args) | 
|---|
| [329] | 36 | { | 
|---|
| [551] | 37 | HAB hab2; | 
|---|
|  | 38 | HMQ hmq2; | 
|---|
| [2] | 39 | ULONG cntr = 0; | 
|---|
|  | 40 |  | 
|---|
|  | 41 | priority_bumped(); | 
|---|
|  | 42 | hab2 = WinInitialize(0); | 
|---|
| [551] | 43 | if (hab2) { | 
|---|
|  | 44 | hmq2 = WinCreateMsgQueue(hab2, 0); | 
|---|
|  | 45 | if (hmq2) { | 
|---|
|  | 46 | WinCancelShutdown(hmq2, TRUE); | 
|---|
|  | 47 | if (!DosCreateEventSem(NULL, &hevTimerSem, 0, FALSE)) { | 
|---|
|  | 48 | for (;;) { | 
|---|
|  | 49 | if (DosWaitEventSem(hevTimerSem, 3000) != ERROR_TIMEOUT) | 
|---|
|  | 50 | break; | 
|---|
|  | 51 | cntr++; | 
|---|
|  | 52 | if (hwndTree && !(cntr % 3)) | 
|---|
|  | 53 | PostMsg(hwndTree, UM_TIMER, MPVOID, MPVOID); | 
|---|
|  | 54 | if (hwndBubble && WinIsWindowVisible(hwndBubble)) | 
|---|
|  | 55 | PostMsg(hwndBubble, UM_TIMER, MPVOID, MPVOID); | 
|---|
|  | 56 | if (DataHwnd) | 
|---|
|  | 57 | PostMsg(DataHwnd, UM_TIMER, MPVOID, MPVOID); | 
|---|
|  | 58 | } | 
|---|
|  | 59 | DosCloseEventSem(hevTimerSem); | 
|---|
| [2] | 60 | } | 
|---|
|  | 61 | WinDestroyMsgQueue(hmq2); | 
|---|
|  | 62 | } | 
|---|
|  | 63 | WinTerminate(hab2); | 
|---|
|  | 64 | } | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
| [329] | 67 | //== StartTimer() return TRUE can start thread == | 
|---|
| [2] | 68 |  | 
|---|
| [551] | 69 | BOOL StartTimer(void) | 
|---|
| [329] | 70 | { | 
|---|
| [551] | 71 | INT rc = _beginthread(TimerThread, NULL, 32768, (PVOID) 0); | 
|---|
| [329] | 72 |  | 
|---|
|  | 73 | if (rc == -1) | 
|---|
| [551] | 74 | Runtime_Error(pszSrcFile, __LINE__, | 
|---|
|  | 75 | GetPString(IDS_COULDNTSTARTTHREADTEXT)); | 
|---|
| [329] | 76 |  | 
|---|
|  | 77 | return rc != -1; | 
|---|
| [2] | 78 | } | 
|---|
|  | 79 |  | 
|---|
| [551] | 80 | void StopTimer(void) | 
|---|
| [329] | 81 | { | 
|---|
| [2] | 82 | DosPostEventSem(hevTimerSem); | 
|---|
|  | 83 | } | 
|---|