- Timestamp:
- Aug 31, 1999, 5:06:17 PM (26 years ago)
- Location:
- trunk/src/winmm
- Files:
-
- 2 added
- 3 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/winmm/makefile
r604 r756 1 # $Id: makefile,v 1. 8 1999-08-21 12:29:32 sandervlExp $1 # $Id: makefile,v 1.9 1999-08-31 15:04:10 phaller Exp $ 2 2 3 3 # … … 21 21 TARGET = winmm 22 22 23 OBJS = winmm.obj os2timer.obj waveout.obj dwaveout.obj timegettime.obj \23 OBJS = os2timer.obj waveout.obj dwaveout.obj time.obj \ 24 24 wavein.obj aux.obj auxos2.obj mixer.obj \ 25 25 midi.obj irtmidi.obj midistrm.obj initterm.obj mci.obj joy.obj \ … … 46 46 47 47 driver.obj: driver.cpp 48 winmm.obj: winmm.cpp 49 os2timer.obj: os2timer.h wintimer.h 48 os2timer.obj: os2timer.cpp os2timer.h time.h 50 49 waveout.obj: waveout.cpp dwaveout.h 51 50 wavein.obj: wavein.cpp … … 60 59 irtmidi.obj: irtmidi.cpp irtmidi.hpp 61 60 dwaveout.obj: dwaveout.cpp dwaveout.h $(PDWIN32_INCLUDE)\vmutex.h 62 time gettime.obj: timegettime.cpp61 time.obj: time.cpp 63 62 initterm.obj: initterm.cpp aux.h 64 63 playsound.obj: playsound.cpp -
trunk/src/winmm/os2timer.cpp
r668 r756 1 /* $Id: os2timer.cpp,v 1. 7 1999-08-24 21:21:11phaller Exp $ */1 /* $Id: os2timer.cpp,v 1.8 1999-08-31 15:04:10 phaller Exp $ */ 2 2 3 3 /* … … 5 5 * 6 6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) 7 * Copyright 1999 Patrick Haller (phaller@gmx.net) 7 8 * 8 9 * Project Odin Software License can be found in LICENSE.TXT … … 20 21 #include <os2wrap.h> //Odin32 OS/2 api wrappers 21 22 #include <process.h> 22 #include "win32type.h" 23 #include "wintimer.h" 23 #include <win32type.h> 24 24 #include <wprocess.h> 25 #include <misc.h> 26 27 #include "time.h" 25 28 #include "os2timer.h" 26 #include "misc.h"27 29 28 30 … … 32 34 ****************************************************************************/ 33 35 34 #if 035 //@@@PH started new implementation36 typedef struct _MMTIMEREVENT37 {38 struct _MMTIMEREVENT* prev;39 struct _MMTIMEREVENT* next;40 41 DWORD id; // event id42 DWORD timeScheduled; // system time to fire event43 DWORD timePeriod; // period if periodic event44 TID tidCaller; // thread ID of caller thread45 DWORD dwUser; // user supplied value46 LPTIMERCALLBACK lpCallback; // address to call47 DWORD dwFlags; // event flags48 } MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT;49 50 typedef struct _MMTIMERRESOLUTION51 {52 struct _MMTIMERRESOLUTION* prev;53 struct _MMTIMERRESOLUTION* next;54 55 DWORD dwResolution; // requested resolution for block56 } MMTIMERRESOLUTION, *PMMTIMERRESOLUTION, *LPMMTIMERRESOLUTION;57 58 /*59 enterResolutionScope60 leaveResolutionScope61 62 addEvent63 removeEvent64 rescheduleEvent65 callbackCaller66 */67 #endif68 36 69 37 /**************************************************************************** … … 76 44 77 45 46 /**************************************************************************** 47 * Class: OS2TimerResolution * 48 ****************************************************************************/ 49 50 51 /***************************************************************************** 52 * Name : OS2TimerResolution::OS2TimerResolution 53 * Purpose : create a new entry in the resolution stack 54 * Parameters: - 55 * Variables : 56 * Result : 57 * Remark : 58 * Status : UNTESTED STUB 59 * 60 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 61 *****************************************************************************/ 62 63 OS2TimerResolution::OS2TimerResolution(int dwPeriod) 64 { 65 // add to linked list 66 OS2TimerResolution *timeRes = OS2TimerResolution::sTimerResolutions; 67 68 if(timeRes != NULL) 69 { 70 while(timeRes->next != NULL) 71 { 72 timeRes = timeRes->next; 73 } 74 timeRes->next = this; 75 } 76 else 77 OS2TimerResolution::sTimerResolutions = this; 78 79 this->dwPeriod = dwPeriod; 80 } 81 82 83 /***************************************************************************** 84 * Name : OS2TimerResolution::~OS2TimerResolution 85 * Purpose : remove entry from the linked list 86 * Parameters: 87 * Variables : 88 * Result : 89 * Remark : 90 * Status : UNTESTED STUB 91 * 92 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 93 *****************************************************************************/ 94 95 OS2TimerResolution::~OS2TimerResolution() 96 { 97 // remove from linked list 98 OS2TimerResolution *timeRes = OS2TimerResolution::sTimerResolutions; 99 100 // leaveResolutionScope() if still entered??? 101 102 if(timeRes != this) 103 { 104 while(timeRes->next != this) 105 { 106 timeRes = timeRes->next; 107 } 108 timeRes->next = this->next; 109 } 110 else 111 OS2TimerResolution::sTimerResolutions = timeRes->next; 112 } 113 114 115 /***************************************************************************** 116 * Name : OS2TimerResolution::enterResolutionScope 117 * Purpose : set the currently requested timer resolution for this entry 118 * Parameters: 119 * Variables : 120 * Result : 121 * Remark : 122 * Status : UNTESTED STUB 123 * 124 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 125 *****************************************************************************/ 126 127 BOOL OS2TimerResolution::enterResolutionScope(int dwPeriod) 128 { 129 OS2TimerResolution* timeRes = new OS2TimerResolution(dwPeriod); 130 if (timeRes != NULL) 131 return TRUE; 132 else 133 return FALSE; 134 } 135 136 137 /***************************************************************************** 138 * Name : OS2TimerResolution::leaveResolutionScope 139 * Purpose : remove specified entry from the list if periods match 140 * Parameters: int dwPeriod 141 * Variables : 142 * Result : TRUE or FALSE 143 * Remark : 144 * Status : UNTESTED STUB 145 * 146 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 147 *****************************************************************************/ 148 149 BOOL OS2TimerResolution::leaveResolutionScope(int dwPeriod) 150 { 151 OS2TimerResolution* timeRes = OS2TimerResolution::sTimerResolutions; 152 153 if (timeRes != NULL) 154 { 155 for(; // walk to the end of the list 156 timeRes->next != NULL; 157 timeRes = timeRes->next) 158 ; 159 160 if (timeRes->dwPeriod == dwPeriod) // do the requested period match? 161 { 162 delete timeRes; // so delete that object 163 return TRUE; // OK, can remove the entry 164 } 165 } 166 return FALSE; // nope, mismatch ! 167 } 168 169 170 /***************************************************************************** 171 * Name : OS2TimerResolution::queryCurrentResolution 172 * Purpose : determine the maximum resolution currently requested 173 * Parameters: 174 * Variables : 175 * Result : 176 * Remark : 177 * Status : UNTESTED STUB 178 * 179 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 180 *****************************************************************************/ 181 182 int OS2TimerResolution::queryCurrentResolution() 183 { 184 OS2TimerResolution *timeRes = OS2TimerResolution::sTimerResolutions; 185 int iMax = -1; 186 187 if (timeRes != NULL) // do we have an entry yet? 188 for (; // walk the linked list 189 timeRes->next != NULL; 190 timeRes = timeRes->next) 191 { 192 if (timeRes->dwPeriod < iMax) // determine minimum time period 193 iMax = timeRes->dwPeriod; 194 } 195 196 return iMax; 197 } 198 199 200 201 202 78 203 /******************************************************************************/ 79 204 /******************************************************************************/ 80 205 OS2Timer::OS2Timer() : TimerSem(0), TimerHandle(0), TimerThreadID(0), 81 206 clientCallback(NULL), TimerStatus(Stopped), fFatal(FALSE) 82 207 { 83 208 OS2Timer *timer = OS2Timer::timers; 84 209 85 if(timer != NULL) { 86 while(timer->next != NULL) { 87 timer = timer->next; 210 if(timer != NULL) 211 { 212 while(timer->next != NULL) 213 { 214 timer = timer->next; 88 215 } 89 216 timer->next = this; 90 217 } 91 else timers = this; 218 else 219 timers = this; 92 220 93 221 TimerThreadID = _beginthread(TimerHlpHandler, NULL, 0x4000, (void *)this); 94 DosSleep(100);222 //@@@PH: why the wait? DosSleep(100); 95 223 } 96 224 /******************************************************************************/ … … 98 226 OS2Timer::~OS2Timer() 99 227 { 100 OS2Timer *timer = OS2Timer::timers;228 OS2Timer *timer = OS2Timer::timers; 101 229 102 230 KillTimer(); 103 231 104 if(timer != this) { 105 while(timer->next != this) { 106 timer = timer->next; 232 if(timer != this) 233 { 234 while(timer->next != this) 235 { 236 timer = timer->next; 107 237 } 108 238 timer->next = this->next; 109 239 } 110 else timers = timer->next; 111 } 112 /******************************************************************************/ 113 /******************************************************************************/ 114 BOOL OS2Timer::StartTimer(int period, int resolution, LPTIMECALLBACK lptc, 115 int dwUser, int fuEvent) 116 { 117 APIRET rc; 118 119 if(TimerThreadID == -1) { 240 else 241 timers = timer->next; 242 } 243 /******************************************************************************/ 244 /******************************************************************************/ 245 BOOL OS2Timer::StartTimer(int period, 246 int resolution, 247 LPTIMECALLBACK lptc, 248 int dwUser, 249 int fuEvent) 250 { 251 APIRET rc; 252 253 if(TimerThreadID == -1) 254 { 120 255 return(FALSE); 121 256 } 122 if(TimerStatus == Stopped) { 257 258 if(TimerStatus == Stopped) 259 { 123 260 clientCallback = lptc; 124 261 userData = dwUser; 125 if(fuEvent == TIME_PERIODIC) 126 rc = DosStartTimer(period, (HSEM)TimerSem, &TimerHandle); 127 else rc = DosAsyncTimer(period, (HSEM)TimerSem, &TimerHandle); 128 if(rc) { 262 263 if(fuEvent == TIME_PERIODIC) 264 rc = DosStartTimer(period, (HSEM)TimerSem, &TimerHandle); 265 else 266 rc = DosAsyncTimer(period, (HSEM)TimerSem, &TimerHandle); 267 268 if(rc) 269 { 270 129 271 #ifdef DEBUG 130 if(fuEvent == TIME_PERIODIC) 131 WriteLog("DosStartTimer failed %d\n", rc); 132 else WriteLog("DosAsyncTimer failed %d\n", rc); 272 if(fuEvent == TIME_PERIODIC) 273 WriteLog("DosStartTimer failed %d\n", rc); 274 else 275 WriteLog("DosAsyncTimer failed %d\n", rc); 133 276 #endif 134 return(FALSE); 135 } 136 TimerStatus = Running; 137 } 138 else return(FALSE); //already running (must use timeKillEvent first) 277 278 return(FALSE); 279 } 280 281 TimerStatus = Running; 282 } 283 else 284 return(FALSE); //already running (must use timeKillEvent first) 285 139 286 return(TRUE); 140 287 } … … 143 290 void OS2Timer::StopTimer() 144 291 { 145 if(TimerStatus == Running) { 146 DosStopTimer(TimerHandle); 147 TimerStatus = Stopped; 292 if(TimerStatus == Running) 293 { 294 DosStopTimer(TimerHandle); 295 TimerStatus = Stopped; 148 296 } 149 297 } … … 154 302 fFatal = TRUE; 155 303 DosStopTimer(TimerHandle); 156 if(DosPostEventSem(TimerSem)) {//something went wrong 157 DosKillThread(TimerThreadID); 158 DosCloseEventSem(TimerSem); 304 if(DosPostEventSem(TimerSem)) 305 { //something went wrong 306 DosKillThread(TimerThreadID); 307 DosCloseEventSem(TimerSem); 159 308 } 160 309 TimerStatus = InActive; … … 192 341 // @@@PH: we're calling the client with PRTYC_TIMECRITICAL !!! 193 342 // It'd be much nicer to call with original priority! 194 // @@@PH: plus the original thread is supposed to stop while the195 // time event is scheduled (DosSuspendThread()) ? It's196 // much like raising a signal (SIGALARM)197 343 198 344 selTIB = SetWin32TIB(); … … 211 357 _endthread(); 212 358 } 213 //****************************************************************************** 214 //****************************************************************************** 215 OS2Timer *OS2Timer::timers = NULL; 216 int OS2Timer::timerPeriod = 0; 217 359 360 361 //****************************************************************************** 362 //****************************************************************************** 363 OS2TimerResolution *OS2TimerResolution::sTimerResolutions = NULL; 364 OS2Timer *OS2Timer::timers = NULL; 365 int OS2Timer::timerPeriod = 0; 366 -
trunk/src/winmm/os2timer.h
r95 r756 1 /* $Id: os2timer.h,v 1. 3 1999-06-10 16:24:34phaller Exp $ */1 /* $Id: os2timer.h,v 1.4 1999-08-31 15:04:11 phaller Exp $ */ 2 2 3 3 #ifndef __OS2TIMER_H__ … … 7 7 * 8 8 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) 9 * Copyright 1999 Patrick Haller (phaller@gmx.net) 9 10 * 10 11 * Project Odin Software License can be found in LICENSE.TXT … … 16 17 #define HTIMER int 17 18 #endif 19 20 21 /**************************************************************************** 22 * Structures * 23 ****************************************************************************/ 24 25 #if 0 26 typedef struct _MMTIMEREVENT 27 { 28 struct _MMTIMEREVENT* prev; 29 struct _MMTIMEREVENT* next; 30 31 DWORD id; // event id 32 DWORD timeScheduled; // system time to fire event 33 DWORD timePeriod; // period if periodic event 34 TID tidCaller; // thread ID of caller thread 35 DWORD dwUser; // user supplied value 36 LPTIMERCALLBACK lpCallback; // address to call 37 DWORD dwFlags; // event flags 38 } MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT; 39 #endif 40 41 /* 42 addEvent 43 removeEvent 44 rescheduleEvent 45 callbackCaller 46 */ 47 48 49 /**************************************************************************** 50 * Class: OS2TimerResolution * 51 ****************************************************************************/ 52 53 class OS2TimerResolution 54 { 55 public: 56 // public entries 57 static BOOL enterResolutionScope(int dwPeriod); // request timer resolution 58 static BOOL leaveResolutionScope(int dwPeriod); // release resolution request 59 static int queryCurrentResolution(); // query maximum resolution 60 61 // public variables 62 int dwPeriod; 63 64 protected: 65 // constructors and destructors 66 OS2TimerResolution(void); 67 OS2TimerResolution(int dwPeriod); 68 ~OS2TimerResolution(); 69 70 // simple linked list 71 static OS2TimerResolution* sTimerResolutions; // list of resolution scoped 72 OS2TimerResolution* next; // link to next entry 73 }; 74 75 76 /**************************************************************************** 77 * Class: OS2Timer * 78 ****************************************************************************/ 18 79 19 80 class OS2Timer
Note:
See TracChangeset
for help on using the changeset viewer.