Changeset 91 for trunk/src/helpers/timer.c
- Timestamp:
- Aug 2, 2001, 10:36:35 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/timer.c
r86 r91 110 110 #include "helpers\linklist.h" 111 111 #include "helpers\math.h" 112 #include "helpers\standards.h" 112 113 #include "helpers\threads.h" 113 114 #include "helpers\timer.h" … … 248 249 { 249 250 PLINKLIST pllXTimers = (PLINKLIST)pSet->pvllXTimers; 250 PLISTNODE pNode = lstQueryFirstNode(pllXTimers);251 if (! pNode)251 ULONG cTimers = lstCountItems(pllXTimers); 252 if (!cTimers) 252 253 { 253 254 // no XTimers running: … … 268 269 // we have timers: 269 270 270 ULONG ulOldPMTimeout = pSet->ulPMTimeout; 271 272 if (!pNode->pNext) 271 ULONG ulOldPMTimeout = pSet->ulPMTimeout; 272 273 PLISTNODE pNode = lstQueryFirstNode(pllXTimers); 274 PXTIMER pTimer1 = (PXTIMER)pNode->pItemData; 275 276 if (cTimers == 1) 273 277 { 274 278 // only one timer: 275 279 // that's easy 276 PXTIMER pTimer = (PXTIMER)pNode->pItemData; 277 pSet->ulPMTimeout = pTimer->ulTimeout; 278 } 279 else if (!pNode->pNext->pNext) 280 pSet->ulPMTimeout = pTimer1->ulTimeout; 281 } 282 else if (cTimers == 2) 280 283 { 281 284 // exactly two timers: 282 285 // find the greatest common denominator 283 PXTIMER pTimer1 = (PXTIMER)pNode->pItemData, 284 pTimer2 = (PXTIMER)pNode->pNext->pItemData; 286 PXTIMER pTimer2 = (PXTIMER)pNode->pNext->pItemData; 285 287 286 288 pSet->ulPMTimeout = mathGCD(pTimer1->ulTimeout, … … 289 291 else 290 292 { 291 // severaltimers:293 // more than two timers: 292 294 // run through all timers and find the greatest 293 295 // common denominator of all frequencies... 294 295 ULONG cTimers = lstCountItems(pllXTimers);296 296 int *paInts = (int*)_alloca(sizeof(int) * cTimers), 297 297 i = 0; 298 298 299 _Pmpf(("Recalculating, got %d timers %d", cTimers));299 // _Pmpf(("Recalculating, got %d timers", cTimers)); 300 300 301 301 // fill an array of integers with the … … 303 303 while (pNode) 304 304 { 305 PXTIMER pTimer= (PXTIMER)pNode->pItemData;306 307 _Pmpf((" timeout %d is %d", i, pTimer->ulTimeout));308 309 paInts[i++] = pTimer ->ulTimeout;305 pTimer1 = (PXTIMER)pNode->pItemData; 306 307 // _Pmpf((" timeout %d is %d", i, pTimer1->ulTimeout)); 308 309 paInts[i++] = pTimer1->ulTimeout; 310 310 311 311 pNode = pNode->pNext; … … 314 314 pSet->ulPMTimeout = mathGCDMulti(paInts, 315 315 cTimers); 316 _Pmpf(("--> GCD is %d", pSet->ulPMTimeout));317 } 318 319 if ( ( pSet->idPMTimerRunning == 0) // timer not running?316 // _Pmpf(("--> GCD is %d", pSet->ulPMTimeout)); 317 } 318 319 if ( (!pSet->idPMTimerRunning) // timer not running? 320 320 || (pSet->ulPMTimeout != ulOldPMTimeout) // timeout changed? 321 321 ) … … 355 355 USHORT usPMTimerID) 356 356 { 357 PXTIMERSET pSet = NULL; 358 359 pSet = (PXTIMERSET)malloc(sizeof(*pSet)); 357 PXTIMERSET pSet = NEW(XTIMERSET); 360 358 if (pSet) 361 359 { … … 434 432 *@@added V0.9.9 (2001-02-28) [umoeller] 435 433 *@@changed V0.9.12 (2001-05-12) [umoeller]: added mutex protection 436 *@@changed V0.9.12 (2001-05-24) [umoeller]: fixed crash if timer was deleted during winproc's WM_TIMER processing 434 *@@changed V0.9.12 (2001-05-24) [umoeller]: fixed crash if this got called during tmrTimerTick 435 *@@changed V0.9.14 (2001-08-01) [umoeller]: fixed mem overwrite which might have caused crashes if this got called during tmrTimerTick 437 436 */ 438 437 … … 498 497 PFNWP pfnwp = (PFNWP)WinQueryWindowPtr(pTimer->hwndTarget, 499 498 QWP_PFNWP); 499 500 // moved this up V0.9.14 (2001-08-01) [umoeller] 501 pTimer->ulNextFire = ulTimeNow + pTimer->ulTimeout; 502 500 503 // call the window proc DIRECTLY 501 504 pfnwp(pTimer->hwndTarget, … … 511 514 // the list, so we'll see it in this loop 512 515 513 pTimer->ulNextFire = ulTimeNow + pTimer->ulTimeout; 516 // V0.9.14 (2001-08-01) [umoeller] 517 518 // DO NOT REFERENCE pTimer AFTER THIS CODE; 519 // tmrTimerTick might have removed the timer, 520 // and since the list is auto-free, pTimer 521 // might have been freed!! 514 522 } 515 523 else … … 598 606 599 607 // fix the timeout... we allow only multiples of 600 // 2 0, and it must be at least 20(otherwise our608 // 25, and it must be at least 25 (otherwise our 601 609 // internal master timer calculations will fail) 602 610 // V0.9.14 (2001-07-07) [umoeller] … … 607 615 608 616 // check if this timer exists already 609 pTimer = FindTimer(pSet, 610 hwnd, 611 usTimerID); 612 if (pTimer) 617 if (pTimer = FindTimer(pSet, 618 hwnd, 619 usTimerID)) 613 620 { 614 621 // exists already: reset only … … 617 624 &ulTimeNow, sizeof(ulTimeNow)); 618 625 pTimer->ulNextFire = ulTimeNow + ulTimeout; 619 usrc = pTimer->usTimerID;626 usrc = usTimerID; 620 627 } 621 628 else 622 629 { 623 630 // new timer needed: 624 pTimer = (PXTIMER)malloc(sizeof(XTIMER)); 625 if (pTimer) 631 if (pTimer = NEW(XTIMER)) 626 632 { 627 633 ULONG ulTimeNow; … … 635 641 lstAppendItem(pllXTimers, 636 642 pTimer); 637 usrc = pTimer->usTimerID;643 usrc = usTimerID; 638 644 } 639 645 } … … 673 679 if (pSet && pSet->pvllXTimers) 674 680 { 675 PLINKLIST pllXTimers = (PLINKLIST)pSet->pvllXTimers; 676 BOOL fLocked = FALSE; 681 // PLINKLIST pllXTimers = (PLINKLIST)pSet->pvllXTimers; 677 682 678 683 PXTIMER pTimer = FindTimer(pSet,
Note:
See TracChangeset
for help on using the changeset viewer.