fix clock_gettime() con macOS <10.12 (not provided by base)

pull/357/head
Davide Gerhard 2019-05-11 11:14:59 +02:00
rodzic 94d03f9004
commit b7071869d1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7CBEFA144857DC97
4 zmienionych plików z 45 dodań i 30 usunięć

Wyświetl plik

@ -57,23 +57,4 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
}
}
#ifdef _DARWIN_FEATURE_CLOCK_GETTIME
/**
* Missing POSIX RealTime/Monotonic Clock
*/
#include <mach/mach_time.h>
int clock_gettime(int clk_id, struct timespec *t) {
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
uint64_t time;
time = mach_absolute_time();
double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom);
double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9);
t->tv_sec = seconds;
t->tv_nsec = nseconds;
return 0;
}
#endif
#endif // APPLE Compatibility
#endif // __APPLE_

Wyświetl plik

@ -31,13 +31,45 @@ int pthread_barrier_wait(pthread_barrier_t *barrier);
#endif // PTHREAD_BARRIER_H_
// <time.h>
#ifndef CLOCK_REALTIME
# define CLOCK_REALTIME 0
#endif
#ifndef CLOCK_MONOTONIC
# define CLOCK_MONOTONIC 0
#endif
// macOS < 10.12 doesn't have clock_gettime()
#include <time.h>
#if !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC)
#endif // APPLE Compatibility
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 6
typedef int clockid_t;
#include <sys/time.h>
#include <mach/mach_time.h>
// here to avoid problem on linking of qrtplib
inline int clock_gettime( clockid_t clk_id, struct timespec *ts )
{
int ret = -1;
if ( ts )
{
if ( CLOCK_REALTIME == clk_id )
{
struct timeval tv;
ret = gettimeofday(&tv, NULL);
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;
}
else if ( CLOCK_MONOTONIC == clk_id )
{
const uint64_t t = mach_absolute_time();
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
const uint64_t tdiff = t * timebase.numer / timebase.denom;
ts->tv_sec = tdiff / 1000000000;
ts->tv_nsec = tdiff % 1000000000;
ret = 0;
}
}
return ret;
}
#endif // CLOCK_REALTIME and CLOCK_MONOTONIC
#endif // __APPLE__

Wyświetl plik

@ -1,7 +1,6 @@
project(qrtplib)
set (qrtplib_HEADERS
../custom/apple/apple_compat.h
rtcpapppacket.h
rtcpbyepacket.h
rtcpcompoundpacket.h
@ -44,7 +43,6 @@ set (qrtplib_HEADERS
)
set(qrtplib_SOURCES
../custom/apple/apple_compat.c
rtcpapppacket.cpp
rtcpbyepacket.cpp
rtcpcompoundpacket.cpp

Wyświetl plik

@ -60,6 +60,10 @@
#define CEPOCH 11644473600000000ULL
#endif // RTP_HAVE_VSUINT64SUFFIX
#ifdef __APPLE__
#include "../custom/apple/apple_compat.h"
#endif
namespace qrtplib
{