Ticket #5865: 5865-darwin-nonthreaded.patch

File 5865-darwin-nonthreaded.patch, 1.3 KB (added by pcapriotti, 3 years ago)
  • rts/posix/Clock.h

    From 67904adafaa185cb1489dfeedb5415cc0057a88c Mon Sep 17 00:00:00 2001
    From: Paolo Capriotti <[email protected]>
    Date: Sat, 24 Mar 2012 02:19:43 +0000
    Subject: [PATCH] Use monotonic time function for darwin (#5865)
    
    ---
     rts/posix/Clock.h   |    3 +++
     rts/posix/GetTime.c |   11 +++++++++++
     2 files changed, 14 insertions(+), 0 deletions(-)
    
    diff --git a/rts/posix/Clock.h b/rts/posix/Clock.h
    index 5062023..2c71d7a 100644
    a b  
    2727# else 
    2828#  define CLOCK_ID CLOCK_REALTIME 
    2929# endif 
     30#elif defined(darwin_HOST_OS) 
     31# include <mach/mach.h> 
     32# include <mach/mach_time.h> 
    3033#endif 
    3134 
    3235#endif /* POSIX_CLOCK_H */ 
  • rts/posix/GetTime.c

    diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
    index 4abc82f..549b3b0 100644
    a b Time getProcessElapsedTime(void) 
    7171 
    7272    clock_gettime(CLOCK_ID, &ts); 
    7373    return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec); 
     74#elif defined(darwin_HOST_OS) 
     75    uint64_t time = mach_absolute_time(); 
     76    static double scaling_factor = 0.0; 
     77 
     78    if (scaling_factor == 0.0) { 
     79        mach_timebase_info_data_t info; 
     80        (void) mach_timebase_info(&info); 
     81        scaling_factor = (double)info.numer / (double)info.denom; 
     82    } 
     83 
     84    return (Time)((double)time * scaling_factor); 
    7485#else 
    7586    struct timeval tv; 
    7687