Changeset 24 for trunk/kHlp


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

darwin porting.

Location:
trunk/kHlp
Files:
2 added
2 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
  • trunk/kHlp/Makefile.kmk

    r5 r24  
    6565        Generic/kHlpInt2Ascii.c \
    6666        \
    67     Generic/kHlpGetEnvUZ.c \
     67        Generic/kHlpGetEnvUZ.c \
    6868        \
    6969        Generic/kHlpGetExt.c \
     
    7878        Bare/kHlpBareProcess.c \
    7979        Bare/kHlpBareThread.c \
     80
     81kHlpBareStatic_SOURCES.darwin = \
     82        Bare/kHlpSys-darwin.c
    8083
    8184#
     
    99102        Generic/kHlpInt2Ascii.c \
    100103        \
    101     Generic/kHlpGetEnvUZ.c \
     104        Generic/kHlpGetEnvUZ.c \
    102105        \
    103106        Generic/kHlpGetExt.c \
     
    111114        CRT/kHlpCRTString.cpp \
    112115
     116kHlpCRTStatic_SOURCES.darwin = \
     117        Bare/kHlpSys-darwin.c
     118
    113119
    114120# Generate the rules
Note: See TracChangeset for help on using the changeset viewer.