diff options
Diffstat (limited to '3rdparty/portmidi/porttime/ptlinux.c')
-rw-r--r-- | 3rdparty/portmidi/porttime/ptlinux.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/3rdparty/portmidi/porttime/ptlinux.c b/3rdparty/portmidi/porttime/ptlinux.c index c58107c36ad..7302e212311 100644 --- a/3rdparty/portmidi/porttime/ptlinux.c +++ b/3rdparty/portmidi/porttime/ptlinux.c @@ -29,7 +29,7 @@ CHANGE LOG #include <unistd.h> #include <sys/types.h> #include "porttime.h" -#include "sys/time.h" +#include "time.h" #include "sys/resource.h" #include "sys/timeb.h" #include "pthread.h" @@ -38,7 +38,7 @@ CHANGE LOG #define FALSE 0 static int time_started_flag = FALSE; -static struct timeval time_offset = {0, 0}; +static struct timespec time_offset = {0, 0}; static pthread_t pt_thread_pid; static int pt_thread_created = FALSE; @@ -79,7 +79,8 @@ static void *Pt_CallbackProc(void *p) PtError Pt_Start(int resolution, PtCallback *callback, void *userData) { if (time_started_flag) return ptNoError; - gettimeofday(&time_offset, NULL); /* need this set before process runs */ + /* need this set before process runs: */ + clock_gettime(CLOCK_MONOTONIC_RAW, &time_offset); if (callback) { int res; pt_callback_parameters *parms = (pt_callback_parameters *) @@ -99,7 +100,7 @@ PtError Pt_Start(int resolution, PtCallback *callback, void *userData) } -PtError Pt_Stop() +PtError Pt_Stop(void) { /* printf("Pt_Stop called\n"); */ pt_callback_proc_id++; @@ -112,20 +113,20 @@ PtError Pt_Stop() } -int Pt_Started() +int Pt_Started(void) { return time_started_flag; } -PtTimestamp Pt_Time() +PtTimestamp Pt_Time(void) { - long seconds, milliseconds; - struct timeval now; - gettimeofday(&now, NULL); + long seconds, ms; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC_RAW, &now); seconds = now.tv_sec - time_offset.tv_sec; - milliseconds = now.tv_usec - time_offset.tv_usec; - return seconds * 1000 + milliseconds; + ms = (now.tv_nsec - time_offset.tv_nsec) / 1000000; /* round down */ + return seconds * 1000 + ms; } @@ -133,6 +134,3 @@ void Pt_Sleep(int32_t duration) { usleep(duration * 1000); } - - - |