mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 04:45:58 +01:00
util/time: move timespec_sub
to time utilities
This commit is contained in:
parent
c9c31f803e
commit
363bf44a35
3 changed files with 19 additions and 11 deletions
|
@ -13,4 +13,10 @@ uint32_t get_current_time_msec(void);
|
||||||
*/
|
*/
|
||||||
int64_t timespec_to_msec(const struct timespec *a);
|
int64_t timespec_to_msec(const struct timespec *a);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtracts timespec `b` from timespec `a`, and stores the difference in `r`.
|
||||||
|
*/
|
||||||
|
void timespec_sub(struct timespec *r, const struct timespec *a,
|
||||||
|
const struct timespec *b);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
util/log.c
12
util/log.c
|
@ -8,6 +8,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
#include "util/time.h"
|
||||||
|
|
||||||
static bool colored = true;
|
static bool colored = true;
|
||||||
static enum wlr_log_importance log_importance = WLR_ERROR;
|
static enum wlr_log_importance log_importance = WLR_ERROR;
|
||||||
|
@ -27,17 +28,6 @@ static const char *verbosity_headers[] = {
|
||||||
[WLR_DEBUG] = "[DEBUG]",
|
[WLR_DEBUG] = "[DEBUG]",
|
||||||
};
|
};
|
||||||
|
|
||||||
static void timespec_sub(struct timespec *r, const struct timespec *a,
|
|
||||||
const struct timespec *b) {
|
|
||||||
const long NSEC_PER_SEC = 1000000000;
|
|
||||||
r->tv_sec = a->tv_sec - b->tv_sec;
|
|
||||||
r->tv_nsec = a->tv_nsec - b->tv_nsec;
|
|
||||||
if (r->tv_nsec < 0) {
|
|
||||||
r->tv_sec--;
|
|
||||||
r->tv_nsec += NSEC_PER_SEC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_start_time(void) {
|
static void init_start_time(void) {
|
||||||
if (start_time.tv_sec >= 0) {
|
if (start_time.tv_sec >= 0) {
|
||||||
return;
|
return;
|
||||||
|
|
12
util/time.c
12
util/time.c
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include "util/time.h"
|
#include "util/time.h"
|
||||||
|
|
||||||
|
const long NSEC_PER_SEC = 1000000000;
|
||||||
|
|
||||||
int64_t timespec_to_msec(const struct timespec *a) {
|
int64_t timespec_to_msec(const struct timespec *a) {
|
||||||
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
||||||
}
|
}
|
||||||
|
@ -13,3 +15,13 @@ uint32_t get_current_time_msec(void) {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
return timespec_to_msec(&now);
|
return timespec_to_msec(&now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void timespec_sub(struct timespec *r, const struct timespec *a,
|
||||||
|
const struct timespec *b) {
|
||||||
|
r->tv_sec = a->tv_sec - b->tv_sec;
|
||||||
|
r->tv_nsec = a->tv_nsec - b->tv_nsec;
|
||||||
|
if (r->tv_nsec < 0) {
|
||||||
|
r->tv_sec--;
|
||||||
|
r->tv_nsec += NSEC_PER_SEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue