packages feed

clock 0.3 → 0.4.0.1

raw patch · 2 files changed

+53/−12 lines, 2 files

Files

clock.cabal view
@@ -1,25 +1,27 @@ name:          clock-version:       0.3+version:       0.4.0.1 stability:     stable synopsis:      High-resolution clock functions: monotonic, realtime, cputime. description:   A package for convenient access to high-resolution clock and-               timer functions of different operating systems.+               timer functions of different operating systems via a unified API.                .-               POSIX layer was developed by Cetin Sert in 2009.+               POSIX code and surface API was developed by Cetin Sert in 2009.                .-               Windows layer was contributed by Eugene Kirpichov in 2010.+               Windows code was contributed by Eugene Kirpichov in 2010.                .-               Both layers share the same surface API.+               FreeBSD code was contributed by Finn Espen Gundersen on 2013-10-14.                .+               OS X code was contributed by Gerolf Seitz on 2013-10-15.+               .                [Version Scheme]                Major-@/R/@-ewrite . New-@/F/@-unctionality . @/I/@-mprovementAndBugFixes . @/P/@-ackagingOnly                .                * @PackagingOnly@ changes are made for quality assurance reasons. -copyright:     Copyright © Cetin Sert 2009-2012, Eugene Kirpichov 2010+copyright:     Copyright © Cetin Sert 2009-2013, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013 license:       BSD3 license-file:  LICENSE-author:        Cetin Sert <cetin@corsis.eu>, Corsis Research; Eugene Kirpichov <ekirpichov@gmail.com>+author:        Cetin Sert <cetin@corsis.eu>, Corsis Research maintainer:    Cetin Sert <cetin@corsis.eu>, Corsis Research homepage:      http://corsis.github.com/clock/ bug-reports:   http://corsis.github.com/clock/issues
csec/clock.c view
@@ -119,12 +119,43 @@ // ***********************  #include <time.h>+#ifdef __MACH__+  #include <mach/clock.h>+  #include <mach/mach.h>+  #define CLOCK_ID_T clock_id_t+  #define CLOCK_MONOTONIC SYSTEM_CLOCK+  #define CLOCK_REALTIME CALENDAR_CLOCK+  #define CLOCK_PROCESS_CPUTIME_ID SYSTEM_CLOCK+  #define CLOCK_THREAD_CPUTIME_ID SYSTEM_CLOCK+#else+  #define CLOCK_ID_T clockid_t+#endif -void time_(clockid_t clock, long* t)+// due to missing define in FreeBSD 9.0 and 9.1 (http://lists.freebsd.org/pipermail/freebsd-stable/2013-September/075095.html)+#ifndef CLOCK_PROCESS_CPUTIME_ID+  #define CLOCK_PROCESS_CPUTIME_ID 15+#endif++void time_(CLOCK_ID_T clock, long* t) {+  #ifdef __MACH__+    // OS X does not have clock_gettime, use clock_get_time+    // see http://stackoverflow.com/questions/11680461/monotonic-clock-on-osx+    clock_serv_t cclock;+    mach_timespec_t mts;+    struct timespec* ts;+    host_get_clock_service(mach_host_self(), clock, &cclock);+    clock_get_time(cclock, &mts);+    mach_port_deallocate(mach_task_self(), cclock);+    ts = (struct timespec*)t;+    ts->tv_sec = mts.tv_sec;+    ts->tv_nsec = mts.tv_nsec;+  #else+    clock_gettime(clock, (struct timespec*)t);+  #endif -  clock_gettime(clock, (struct timespec*)t); + /*struct timespec a;    clock_gettime(clock, &a);@@ -155,10 +186,18 @@ }  -void res_(clockid_t clock, long* t)+void res_(CLOCK_ID_T clock, long* t) {--  clock_getres(clock, (struct timespec*)t);+  #ifdef __MACH__+    clock_serv_t cclock;+    int nsecs;+    mach_msg_type_number_t count;+    host_get_clock_service(mach_host_self(), clock, &cclock);+    clock_get_attributes(cclock, CLOCK_GET_TIME_RES, (clock_attr_t)&nsecs, &count);+    mach_port_deallocate(mach_task_self(), cclock);+  #else+    clock_getres(clock, (struct timespec*)t);+  #endif  /*struct timespec a;