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