fix: clock_gettime instead of clock
Clang Build CI / build-release (push) Has been cancelled
Clang Build CI / run-no-video (push) Has been cancelled
Clang Build CI / run-video (push) Has been cancelled
Clang Lint CI / lint-no-video (push) Successful in 1m14s
Clang Lint CI / lint-video (push) Successful in 1m16s
Clang Build CI / build-release (push) Has been cancelled
Clang Build CI / run-no-video (push) Has been cancelled
Clang Build CI / run-video (push) Has been cancelled
Clang Lint CI / lint-no-video (push) Successful in 1m14s
Clang Lint CI / lint-video (push) Successful in 1m16s
This commit is contained in:
+7
-1
@@ -7,7 +7,13 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "tempo.h"
|
#include "tempo.h"
|
||||||
|
|
||||||
static long now_ms() { return 1000 * clock() / CLOCKS_PER_SEC; }
|
static long now_ms() {
|
||||||
|
struct timespec ts;
|
||||||
|
if (clock_gettime(CLOCK_REALTIME, &ts) != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1000 * ts.tv_sec + ts.tv_nsec / 1e6;
|
||||||
|
}
|
||||||
|
|
||||||
static void reset_tap_chain(Tempo *tempo, long t) {
|
static void reset_tap_chain(Tempo *tempo, long t) {
|
||||||
tempo->last_reset = t;
|
tempo->last_reset = t;
|
||||||
|
|||||||
+8
-4
@@ -1,3 +1,4 @@
|
|||||||
|
#include <bits/time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@
|
|||||||
void timer_init(Timer *timer, const unsigned int target) {
|
void timer_init(Timer *timer, const unsigned int target) {
|
||||||
timer->counter = 0;
|
timer->counter = 0;
|
||||||
timer->target = target;
|
timer->target = target;
|
||||||
timer->start = clock();
|
clock_gettime(CLOCK_REALTIME, &timer->start);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool timer_inc(Timer *timer) {
|
bool timer_inc(Timer *timer) {
|
||||||
@@ -17,13 +18,16 @@ bool timer_inc(Timer *timer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double timer_reset(Timer *timer) {
|
double timer_reset(Timer *timer) {
|
||||||
clock_t stop;
|
struct timespec stop;
|
||||||
double secs;
|
double secs;
|
||||||
double per_secs;
|
double per_secs;
|
||||||
|
|
||||||
stop = clock();
|
if (clock_gettime(CLOCK_REALTIME, &stop) != 0) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
secs = (double)(stop - timer->start) / CLOCKS_PER_SEC;
|
secs = (double)(stop.tv_sec - timer->start.tv_sec) +
|
||||||
|
(double)(stop.tv_nsec - timer->start.tv_nsec) / 1e9;
|
||||||
per_secs = (double)timer->counter / secs;
|
per_secs = (double)timer->counter / secs;
|
||||||
|
|
||||||
timer->start = stop;
|
timer->start = stop;
|
||||||
|
|||||||
+1
-1
@@ -280,7 +280,7 @@ typedef struct StateBackgroundWriteArgs {
|
|||||||
// timer.c
|
// timer.c
|
||||||
|
|
||||||
typedef struct Timer {
|
typedef struct Timer {
|
||||||
clock_t start;
|
struct timespec start;
|
||||||
unsigned int counter;
|
unsigned int counter;
|
||||||
unsigned int target;
|
unsigned int target;
|
||||||
} Timer;
|
} Timer;
|
||||||
|
|||||||
Reference in New Issue
Block a user