Commit f1a5d04d authored by Brieuc Viel's avatar Brieuc Viel
Browse files

fix clock_gettime error on xcode8

parent 63b47ba1
...@@ -117,6 +117,9 @@ static int find_best_clock_id (void) { ...@@ -117,6 +117,9 @@ static int find_best_clock_id (void) {
} }
uint64_t belle_sip_time_ms(void){ uint64_t belle_sip_time_ms(void){
struct timespec ts; struct timespec ts;
#ifdef __APPLE__
#define clock_gettime bc_clock_gettime
#endif
if (clock_gettime(find_best_clock_id(),&ts)==-1){ if (clock_gettime(find_best_clock_id(),&ts)==-1){
belle_sip_error("clock_gettime() error for clock_id=%i: %s",find_best_clock_id(),strerror(errno)); belle_sip_error("clock_gettime() error for clock_id=%i: %s",find_best_clock_id(),strerror(errno));
return 0; return 0;
......
...@@ -80,7 +80,7 @@ static clock_serv_t belle_sip_calandar_clk; ...@@ -80,7 +80,7 @@ static clock_serv_t belle_sip_calandar_clk;
static clock_serv_t belle_sip_system_clk; static clock_serv_t belle_sip_system_clk;
static int belle_sip_clock_serv_ready=FALSE; static int belle_sip_clock_serv_ready=FALSE;
int clock_gettime(clockid_t clk_id, struct timespec *tp) { int bc_clock_gettime(bc_clockid_t clk_id, struct timespec *tp) {
kern_return_t ret; kern_return_t ret;
clock_serv_t clk_serv; clock_serv_t clk_serv;
mach_timespec_t tm; mach_timespec_t tm;
...@@ -97,9 +97,9 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) { ...@@ -97,9 +97,9 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) {
} }
switch (clk_id) { switch (clk_id) {
case CLOCK_REALTIME: case BC_CLOCK_REALTIME:
case CLOCK_MONOTONIC: case BC_CLOCK_MONOTONIC:
clk_serv = (clk_id == CLOCK_REALTIME) ? belle_sip_calandar_clk : belle_sip_system_clk; clk_serv = (clk_id == BC_CLOCK_REALTIME) ? belle_sip_calandar_clk : belle_sip_system_clk;
if (KERN_SUCCESS == (ret = clock_get_time(clk_serv, &tm))) { if (KERN_SUCCESS == (ret = clock_get_time(clk_serv, &tm))) {
tp->tv_sec = tm.tv_sec; tp->tv_sec = tm.tv_sec;
tp->tv_nsec = tm.tv_nsec; tp->tv_nsec = tm.tv_nsec;
...@@ -110,10 +110,10 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) { ...@@ -110,10 +110,10 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) {
retval = -1; retval = -1;
} }
break; break;
case CLOCK_PROCESS_CPUTIME_ID: case BC_CLOCK_PROCESS_CPUTIME_ID:
case CLOCK_THREAD_CPUTIME_ID: case BC_CLOCK_THREAD_CPUTIME_ID:
start = mach_absolute_time(); start = mach_absolute_time();
if (clk_id == CLOCK_PROCESS_CPUTIME_ID) { if (clk_id == BC_CLOCK_PROCESS_CPUTIME_ID) {
getpid(); getpid();
} else { } else {
sched_yield(); sched_yield();
......
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
#define CLOCK_GETTIME_H_ #define CLOCK_GETTIME_H_
#ifdef __APPLE__ #ifdef __APPLE__
typedef enum { typedef enum {
CLOCK_REALTIME, BC_CLOCK_REALTIME,
CLOCK_MONOTONIC, BC_CLOCK_MONOTONIC,
CLOCK_PROCESS_CPUTIME_ID, BC_CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID BC_CLOCK_THREAD_CPUTIME_ID
} clockid_t; } bc_clockid_t;
int clock_gettime(clockid_t clk_id, struct timespec *tp) ; int bc_clock_gettime(bc_clockid_t clk_id, struct timespec *tp) ;
#endif #endif
#endif /* CLOCK_GETTIME_H_ */ #endif /* CLOCK_GETTIME_H_ */
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