opdenkamp/xbmc — Issue #433: OSX: CLOCK_REALTIME/clock_gettime in lib/platform/posix/os_threads.h not compiling
Author: TheChief79
Created: 2012-02-27 13:44:00+00:00
State: open

This does not compile under OSX.

../../../lib/platform/threads/../posix/os-threads.h: In function ‘timespec PLATFORM::GetAbsTime(uint64_t)’:
../../../lib/platform/threads/../posix/os-threads.h:52: error: ‘CLOCK_REALTIME’ was not declared in this scope
../../../lib/platform/threads/../posix/os-threads.h:52: error: ‘clock_gettime’ was not declared in this scope

This patch seems to work for me:

diff --git a/lib/platform/posix/os-threads.h b/lib/platform/posix/os-threads.h
index c37beed..9168617 100644
--- a/lib/platform/posix/os-threads.h
+++ b/lib/platform/posix/os-threads.h
@@ -1,4 +1,8 @@
#pragma once
+#ifdef __APPLE__
+#include
+#include
+#endif
/*
* This file is part of the libCEC(R) library.
*
@@ -49,10 +53,21 @@ namespace PLATFORM
inline struct timespec GetAbsTime(uint64_t iIncreaseBy = 0)
{
struct timespec now;
+#ifdef __APPLE__
+ 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);
+ now.tv_sec = mts.tv_sec;
+ now.tv_nsec = mts.tv_nsec;
+#else
clock_gettime(CLOCK_REALTIME, &now);
+#endif
now.tv_nsec += iIncreaseBy % 1000 * 1000000;
now.tv_sec += iIncreaseBy / 1000 + now.tv_nsec / 1000000000;
now.tv_nsec %= 1000000000;
+
return now;
}