mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 18:27:12 +02:00
more accurate getTickCount for macOS
This commit is contained in:
parent
ef6aa89222
commit
e91eb74f3e
1 changed files with 10 additions and 3 deletions
|
@ -21,6 +21,10 @@
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#ifdef MACOS
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace chronos
|
namespace chronos
|
||||||
{
|
{
|
||||||
|
@ -49,9 +53,12 @@ namespace chronos
|
||||||
inline static long getTickCount()
|
inline static long getTickCount()
|
||||||
{
|
{
|
||||||
#ifdef MACOS
|
#ifdef MACOS
|
||||||
struct timeval now;
|
clock_serv_t cclock;
|
||||||
gettimeofday(&now, NULL);
|
mach_timespec_t mts;
|
||||||
return now.tv_sec*1000 + now.tv_usec / 1000;
|
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||||
|
clock_get_time(cclock, &mts);
|
||||||
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
|
return mts.tv_sec*1000 + mts.tv_nsec / 1000000;
|
||||||
#else
|
#else
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
Loading…
Add table
Reference in a new issue