VirtualBox

Changeset 24 in kStuff for trunk/kHlp/Bare


Ignore:
Timestamp:
Feb 8, 2009 1:58:54 PM (16 years ago)
Author:
bird
Message:

darwin porting.

Location:
trunk/kHlp/Bare
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kHlp/Bare/kHlpBareThread.c

    r2 r24  
    3737
    3838#if K_OS == K_OS_DARWIN
     39# include <mach/mach_time.h>
    3940
    4041#elif K_OS == K_OS_LINUX
     
    5960{
    6061#if K_OS == K_OS_DARWIN
    61     /** @todo mach_wait_until, see gen/nanosleep.c. */
    62     usleep(cMillies * 1000);
     62    static struct mach_timebase_info   s_Info;
     63    static KBOOL                s_fNanoseconds = K_UNKNOWN;
     64    KU64 uNow = mach_absolute_time();
     65    KU64 uDeadline;
     66    KU64 uPeriod;
     67
     68    if (s_fNanoseconds == K_UNKNOWN)
     69    {
     70        if (mach_timebase_info(&s_Info))
     71            s_fNanoseconds = K_TRUE; /* the easy way out */
     72        else if (s_Info.denom == s_Info.numer)
     73            s_fNanoseconds = K_TRUE;
     74        else
     75            s_fNanoseconds = K_FALSE;
     76    }
     77
     78    uPeriod = (KU64)cMillies * 1000 * 1000;
     79    if (!s_fNanoseconds)
     80        uPeriod = (double)uPeriod * s_Info.denom / s_Info.numer; /* Use double to avoid 32-bit trouble. */
     81    uDeadline = uNow + uPeriod;
     82    mach_wait_until(uDeadline);
    6383
    6484#elif K_OS == K_OS_LINUX
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette