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