Changeset 2032


Ignore:
Timestamp:
Jun 14, 2005, 4:59:56 AM (20 years ago)
Author:
bird
Message:

o Fixed bug in getitimer/setitmer, it didn't zero the old value struct

if the timer wasn't running.

o Fixed a bug in ftime(), the time was jolting around.

Location:
trunk/src/emx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.57 to 1.58
    r2031 r2032  
    1212          (included by sys/param.h which is used by lot's of tcpip headers).
    1313          Define _BSD_NAMESPACE_POLLUTION to get it all.
     14        o Fixed bug in getitimer/setitmer, it didn't zero the old value struct
     15          if the timer wasn't running.
     16        o Fixed a bug in __ftime(), the time was jolting around.
    1417
    15182005-06-12: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/src/lib/sys/__ftime.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r2031 r2032  
    1212 *
    1313 */
     14
     15#define CALCDIFF
    1416
    1517
     
    2931#include "syscalls.h"
    3032
     33#ifdef CALCDIFF
    3134/**
    3235 * Calcs the uDiff in formula timeb.millitm = (msecs + uDiff) % 1000.
     
    8992    return uDiff;
    9093}
     94#endif /* CALCDIFF */
    9195
    9296
     
    99103void __ftime(struct timeb *ptr)
    100104{
     105#pragma pack(1)
     106    union last
     107    {
     108        unsigned long long ull;
     109        struct
     110        {
     111            unsigned secs;
     112            unsigned msecs;
     113            short    milli;
     114        } s;
     115    };
    101116    union combined
    102117    {
    103         volatile unsigned long long ull;
    104118        struct
    105119        {
    106120            ULONG       time;
    107121            ULONG       msecs;
     122            UCHAR       hour;
     123            UCHAR       minutes;
     124            UCHAR       seconds;
     125            UCHAR       hundredths;
    108126        } s;
    109127    };
     
    111129    {
    112130        PGINFOSEG       pGIS;
    113         union combined *pCombined;
     131        volatile union combined *pCombined;
    114132    } uGIS;
    115     static unsigned     uDiff;
    116     union combined      Combined;
     133#pragma pack()
     134    static volatile union last LastStatic;
     135    static volatile unsigned uDiff;
    117136
    118137    /*
     
    121140    if (!uGIS.pGIS)
    122141    {
     142#ifdef CALCDIFF
    123143        uDiff = calcdiff();
     144#endif
    124145        uGIS.pGIS = GETGINFOSEG();
    125146    }
     
    128149     * Get the value and convert it to the return format.
    129150     */
    130     Combined = *uGIS.pCombined;
    131     ptr->time       = Combined.s.time;
    132     ptr->millitm    = (Combined.s.msecs + uDiff) % 1000;
     151    /* read times */
     152    union combined  Combined = *uGIS.pCombined;
     153    union last      LastCopy = LastStatic;
     154
     155    /* calc now */
     156    union last Now;
     157    Now.s.secs = Combined.s.seconds;
     158#ifdef CALCDIFF
     159    Now.s.milli = (Combined.s.msecs + uDiff) % 1000;
     160#else
     161    Now.s.milli = (Combined.s.hundredths * 10) | ((Combined.s.msecs + uDiff) % 10);
     162#endif
     163    Now.s.msecs = Combined.s.msecs;
     164
     165    /* validate now */
     166    unsigned uDiffSecs = Now.s.secs - LastCopy.s.secs;
     167    if (!uDiffSecs)
     168    {
     169        int iDiffMilli = Now.s.milli - LastCopy.s.milli;
     170        if (iDiffMilli < 0)
     171        {
     172            uDiff -= -iDiffMilli + 1;
     173            Now = LastCopy;
     174        }
     175    }
     176    else if (uDiffSecs == 1)
     177    {
     178        unsigned    uDiffMsecs = Now.s.msecs - LastCopy.s.msecs;
     179        unsigned    uDiffMilli = Now.s.milli + 1000 - LastCopy.s.milli;
     180        if (uDiffMilli > uDiffMsecs + 500)
     181        {
     182            uDiff += 1000 - Now.s.milli;
     183            Now.s.milli = 0;
     184        }
     185    }
     186
     187    /* update the last know ok value */
     188    LastStatic = Now; /** @todo 8byte + 4 byte exchange! */
     189
     190    /* store the result in the user buffer */
     191    ptr->time       = Now.s.secs;
     192    ptr->millitm    = Now.s.milli;
    133193    ptr->timezone   = 0;
    134194    ptr->dstflag    = 0;
  • trunk/src/emx/src/lib/sys/b_signalTimer.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2031 r2032  
    399399     * This is *not* gonna be very accurate!
    400400     */
    401     if (pOldValue && gfArmed)
    402     {
    403         OldValue.it_interval.tv_sec = guInterval / 1000;
    404         OldValue.it_interval.tv_usec = (guInterval % 1000) * 1000;
    405 
    406         unsigned u = guNext;
    407         u -= signalTimerClock();
    408         if (u <= guInterval)
    409         {
    410             OldValue.it_value.tv_sec = u / 1000;
    411             OldValue.it_value.tv_usec = (u % 1000) * 1000;
    412         }
     401    if (pOldValue)
     402    {
     403        if (gfArmed)
     404        {
     405            OldValue.it_interval.tv_sec = guInterval / 1000;
     406            OldValue.it_interval.tv_usec = (guInterval % 1000) * 1000;
     407
     408            unsigned u = guNext;
     409            u -= signalTimerClock();
     410            if (u <= guInterval)
     411            {
     412                OldValue.it_value.tv_sec = u / 1000;
     413                OldValue.it_value.tv_usec = (u % 1000) * 1000;
     414            }
     415        }
     416        else
     417            memset(pOldValue, 0, sizeof(*pOldValue));
    413418    }
    414419
Note: See TracChangeset for help on using the changeset viewer.