Commit a272d7ac authored by jhugues's avatar jhugues

* Provide work-around for OS X not implementing clock_gettime()



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@5382 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 3a07790a
......@@ -20,7 +20,7 @@
#include <pthread.h>
#elif defined (RTEMS_PURE)
#include <bsp.h>
#endif
#endif
#if defined (_WIN32)
......@@ -28,6 +28,10 @@
#include <windows.h>
#endif
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#if defined (POSIX) && defined (NEED_CLOCK_GETTIME)
#include <sys/time.h>
......@@ -36,7 +40,7 @@ int clock_gettime(int clk_id, struct timespec *tp)
struct timeval now;
int rv = gettimeofday(&now, NULL);
if (rv != 0)
if (rv != 0)
{
return rv;
}
......@@ -80,11 +84,23 @@ int __po_hi_get_time (__po_hi_time_t* mytime)
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
struct timespec ts;
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts.tv_sec = mts.tv_sec;
ts.tv_nsec = mts.tv_nsec;
#else
if (clock_gettime (CLOCK_REALTIME, &ts)!=0)
{
return (__PO_HI_ERROR_CLOCK);
}
#endif
mytime->sec = ts.tv_sec;
mytime->nsec = ts.tv_nsec;
......@@ -275,5 +291,3 @@ int __po_hi_time_copy (__po_hi_time_t* dst, const __po_hi_time_t* src)
dst->nsec = src->nsec;
return (__PO_HI_SUCCESS);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment