Ignore:
Timestamp:
Aug 2, 2001, 10:36:35 PM (24 years ago)
Author:
umoeller
Message:

Misc changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/timer.c

    r86 r91  
    110110#include "helpers\linklist.h"
    111111#include "helpers\math.h"
     112#include "helpers\standards.h"
    112113#include "helpers\threads.h"
    113114#include "helpers\timer.h"
     
    248249{
    249250    PLINKLIST pllXTimers = (PLINKLIST)pSet->pvllXTimers;
    250     PLISTNODE pNode = lstQueryFirstNode(pllXTimers);
    251     if (!pNode)
     251    ULONG   cTimers = lstCountItems(pllXTimers);
     252    if (!cTimers)
    252253    {
    253254        // no XTimers running:
     
    268269        // we have timers:
    269270
    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)
    273277        {
    274278            // only one timer:
    275279            // 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)
    280283        {
    281284            // exactly two timers:
    282285            // find the greatest common denominator
    283             PXTIMER pTimer1 = (PXTIMER)pNode->pItemData,
    284                     pTimer2 = (PXTIMER)pNode->pNext->pItemData;
     286            PXTIMER pTimer2 = (PXTIMER)pNode->pNext->pItemData;
    285287
    286288            pSet->ulPMTimeout = mathGCD(pTimer1->ulTimeout,
     
    289291        else
    290292        {
    291             // several timers:
     293            // more than two timers:
    292294            // run through all timers and find the greatest
    293295            // common denominator of all frequencies...
    294 
    295             ULONG   cTimers = lstCountItems(pllXTimers);
    296296            int     *paInts = (int*)_alloca(sizeof(int) * cTimers),
    297297                    i = 0;
    298298
    299             _Pmpf(("Recalculating, got %d timers %d", cTimers));
     299            // _Pmpf(("Recalculating, got %d timers", cTimers));
    300300
    301301            // fill an array of integers with the
     
    303303            while (pNode)
    304304            {
    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;
    310310
    311311                pNode = pNode->pNext;
     
    314314            pSet->ulPMTimeout = mathGCDMulti(paInts,
    315315                                             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?
    320320             || (pSet->ulPMTimeout != ulOldPMTimeout) // timeout changed?
    321321           )
     
    355355                        USHORT usPMTimerID)
    356356{
    357     PXTIMERSET pSet = NULL;
    358 
    359     pSet = (PXTIMERSET)malloc(sizeof(*pSet));
     357    PXTIMERSET pSet = NEW(XTIMERSET);
    360358    if (pSet)
    361359    {
     
    434432 *@@added V0.9.9 (2001-02-28) [umoeller]
    435433 *@@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
    437436 */
    438437
     
    498497                                PFNWP pfnwp = (PFNWP)WinQueryWindowPtr(pTimer->hwndTarget,
    499498                                                                       QWP_PFNWP);
     499
     500                                // moved this up V0.9.14 (2001-08-01) [umoeller]
     501                                pTimer->ulNextFire = ulTimeNow + pTimer->ulTimeout;
     502
    500503                                // call the window proc DIRECTLY
    501504                                pfnwp(pTimer->hwndTarget,
     
    511514                                    //    the list, so we'll see it in this loop
    512515
    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!!
    514522                            }
    515523                            else
     
    598606
    599607                // fix the timeout... we allow only multiples of
    600                 // 20, and it must be at least 20 (otherwise our
     608                // 25, and it must be at least 25 (otherwise our
    601609                // internal master timer calculations will fail)
    602610                // V0.9.14 (2001-07-07) [umoeller]
     
    607615
    608616                // 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))
    613620                {
    614621                    // exists already: reset only
     
    617624                                    &ulTimeNow, sizeof(ulTimeNow));
    618625                    pTimer->ulNextFire = ulTimeNow + ulTimeout;
    619                     usrc = pTimer->usTimerID;
     626                    usrc = usTimerID;
    620627                }
    621628                else
    622629                {
    623630                    // new timer needed:
    624                     pTimer = (PXTIMER)malloc(sizeof(XTIMER));
    625                     if (pTimer)
     631                    if (pTimer = NEW(XTIMER))
    626632                    {
    627633                        ULONG ulTimeNow;
     
    635641                        lstAppendItem(pllXTimers,
    636642                                      pTimer);
    637                         usrc = pTimer->usTimerID;
     643                        usrc = usTimerID;
    638644                    }
    639645                }
     
    673679        if (pSet && pSet->pvllXTimers)
    674680        {
    675             PLINKLIST pllXTimers = (PLINKLIST)pSet->pvllXTimers;
    676             BOOL fLocked = FALSE;
     681            // PLINKLIST pllXTimers = (PLINKLIST)pSet->pvllXTimers;
    677682
    678683            PXTIMER pTimer = FindTimer(pSet,
Note: See TracChangeset for help on using the changeset viewer.