[10269] | 1 | /* $Id: os2timer.h,v 1.13 2003-10-13 09:18:37 sandervl Exp $ */
|
---|
[95] | 2 |
|
---|
[4] | 3 | #ifndef __OS2TIMER_H__
|
---|
| 4 | #define __OS2TIMER_H__
|
---|
| 5 | /*
|
---|
| 6 | * OS/2 Timer class
|
---|
| 7 | *
|
---|
| 8 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
[756] | 9 | * Copyright 1999 Patrick Haller (phaller@gmx.net)
|
---|
[4] | 10 | *
|
---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 12 | *
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | #ifdef _OS2WIN_H
|
---|
| 16 | #define HEV int
|
---|
| 17 | #define HTIMER int
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[756] | 20 |
|
---|
| 21 | /****************************************************************************
|
---|
[757] | 22 | * Definitions *
|
---|
| 23 | ****************************************************************************/
|
---|
| 24 |
|
---|
[6728] | 25 | /* 2001-09-16 PH
|
---|
| 26 | with the new OS2KRNL's dating 2001-09-14 and later, there is
|
---|
| 27 | a special CLOCKSCALE feature added which allows for much finer
|
---|
| 28 | granularity of the OS/2 system timers up to a maximum resolution
|
---|
| 29 | of 2ms. This is supposed to be enough for most timing issues here.
|
---|
| 30 |
|
---|
| 31 | Note:
|
---|
| 32 | we need to add support for dynamic detection of this feature.
|
---|
| 33 | */
|
---|
[9901] | 34 | #define OS2TIMER_RESOLUTION_MINIMUM 1
|
---|
[2242] | 35 | #define OS2TIMER_RESOLUTION_MAXIMUM 0x7ffffffe
|
---|
[757] | 36 |
|
---|
| 37 |
|
---|
| 38 | /****************************************************************************
|
---|
[756] | 39 | * Structures *
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | /*
|
---|
| 43 | addEvent
|
---|
| 44 | removeEvent
|
---|
| 45 | rescheduleEvent
|
---|
| 46 | callbackCaller
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | /****************************************************************************
|
---|
| 51 | * Class: OS2TimerResolution *
|
---|
| 52 | ****************************************************************************/
|
---|
| 53 |
|
---|
| 54 | class OS2TimerResolution
|
---|
| 55 | {
|
---|
| 56 | public:
|
---|
| 57 | // public entries
|
---|
| 58 | static BOOL enterResolutionScope(int dwPeriod); // request timer resolution
|
---|
| 59 | static BOOL leaveResolutionScope(int dwPeriod); // release resolution request
|
---|
| 60 | static int queryCurrentResolution(); // query maximum resolution
|
---|
[10269] | 61 |
|
---|
[756] | 62 | // public variables
|
---|
| 63 | int dwPeriod;
|
---|
| 64 |
|
---|
| 65 | protected:
|
---|
| 66 | // constructors and destructors
|
---|
| 67 | OS2TimerResolution(void);
|
---|
| 68 | OS2TimerResolution(int dwPeriod);
|
---|
| 69 | ~OS2TimerResolution();
|
---|
| 70 |
|
---|
| 71 | // simple linked list
|
---|
| 72 | static OS2TimerResolution* sTimerResolutions; // list of resolution scoped
|
---|
| 73 | OS2TimerResolution* next; // link to next entry
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | /****************************************************************************
|
---|
| 78 | * Class: OS2Timer *
|
---|
| 79 | ****************************************************************************/
|
---|
| 80 |
|
---|
[4] | 81 | class OS2Timer
|
---|
| 82 | {
|
---|
| 83 | public:
|
---|
| 84 | OS2Timer();
|
---|
| 85 | ~OS2Timer();
|
---|
| 86 |
|
---|
| 87 | void TimerHandler();
|
---|
| 88 | BOOL StartTimer(int period, int resolution, LPTIMECALLBACK lptc,
|
---|
| 89 | int dwUser, int fuEvent);
|
---|
| 90 | void StopTimer();
|
---|
| 91 | void KillTimer();
|
---|
| 92 |
|
---|
[6933] | 93 | DWORD getTimerID() { return timerID; };
|
---|
| 94 | void setTimerID(DWORD id) { timerID = id; };
|
---|
| 95 |
|
---|
[10269] | 96 | #ifdef DEBUG
|
---|
| 97 | LONG addRef();
|
---|
| 98 | #else
|
---|
| 99 | LONG addRef() { return InterlockedIncrement(&refCount); };
|
---|
| 100 | #endif
|
---|
| 101 | LONG getRefCount() { return refCount; };
|
---|
| 102 | LONG release();
|
---|
| 103 |
|
---|
[4] | 104 | protected:
|
---|
| 105 |
|
---|
| 106 | private:
|
---|
| 107 | HEV TimerSem;
|
---|
| 108 | HTIMER TimerHandle;
|
---|
[759] | 109 | HANDLE hTimerThread;
|
---|
| 110 | DWORD TimerThreadID;
|
---|
[4] | 111 | LPTIMECALLBACK clientCallback;
|
---|
| 112 | DWORD userData;
|
---|
[3600] | 113 | DWORD dwFlags; // corresponds with fuEvent
|
---|
[4] | 114 |
|
---|
| 115 | BOOL fFatal;
|
---|
| 116 | int TimerStatus;
|
---|
[6933] | 117 | DWORD timerID;
|
---|
[4] | 118 | enum {
|
---|
| 119 | InActive = 0,
|
---|
| 120 | Running,
|
---|
| 121 | Stopped
|
---|
| 122 | };
|
---|
[10269] | 123 |
|
---|
| 124 | LONG refCount;
|
---|
| 125 |
|
---|
[4] | 126 | static int timerPeriod;
|
---|
| 127 |
|
---|
| 128 | // Linked list management
|
---|
| 129 | OS2Timer* next; // Next Timer
|
---|
| 130 | static OS2Timer* timers; // List of Timer
|
---|
| 131 |
|
---|
| 132 | };
|
---|
| 133 |
|
---|
| 134 | #endif
|
---|