Move the clock_gettime2 and add_time_in_ms implementation to event.c to avoid code duplication.

This commit is contained in:
Reece H. Dunn
2015-12-31 16:51:46 +00:00
parent 56bfebe2fd
commit 2e88afeaa0
4 changed files with 27 additions and 84 deletions
-27
View File
@@ -46,8 +46,6 @@ struct timespec {
};
#endif
enum { ONE_BILLION = 1000000000 };
#ifdef USE_PORTAUDIO
#include "portaudio.h"
@@ -905,28 +903,3 @@ int wave_get_remaining_time(uint32_t sample, uint32_t *time)
}
#endif
void clock_gettime2(struct timespec *ts)
{
struct timeval tv;
if (!ts)
return;
assert(gettimeofday(&tv, NULL) != -1);
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec*1000;
}
void add_time_in_ms(struct timespec *ts, int time_in_ms)
{
if (!ts)
return;
uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms;
while (t_ns >= ONE_BILLION) {
ts->tv_sec += 1;
t_ns -= ONE_BILLION;
}
ts->tv_nsec = (long int)t_ns;
}