Proper timing

This commit is contained in:
topjohnwu 2019-07-07 12:20:47 -07:00
parent 5fcd629f16
commit 291bf93f9d

View File

@ -47,14 +47,14 @@ void su_info::unlock() {
bool su_info::is_fresh() { bool su_info::is_fresh() {
timespec ts; timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
long current = ts.tv_sec * 1000L + ts.tv_nsec / 1000L; long current = ts.tv_sec * 1000L + ts.tv_nsec / 1000000L;
return current - timestamp < 3000; /* 3 seconds */ return current - timestamp < 3000; /* 3 seconds */
} }
void su_info::refresh() { void su_info::refresh() {
timespec ts; timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
timestamp = ts.tv_sec * 1000L + ts.tv_nsec / 1000L; timestamp = ts.tv_sec * 1000L + ts.tv_nsec / 1000000L;
} }
static void database_check(const shared_ptr<su_info> &info) { static void database_check(const shared_ptr<su_info> &info) {