mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-03-09 05:34:22 -04:00
util: add helper to get time in nanoseconds.
Signed-off-by: Sergio Gómez <sergio.g.delreal@gmail.com>
This commit is contained in:
parent
abf80b529e
commit
0e070e93d8
2 changed files with 11 additions and 0 deletions
|
|
@ -6,6 +6,11 @@
|
||||||
|
|
||||||
static const long NSEC_PER_SEC = 1000000000;
|
static const long NSEC_PER_SEC = 1000000000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current time, in nanoseconds.
|
||||||
|
*/
|
||||||
|
int64_t get_current_time_nsec(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current time, in milliseconds.
|
* Get the current time, in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,12 @@ int64_t get_current_time_msec(void) {
|
||||||
return timespec_to_msec(&now);
|
return timespec_to_msec(&now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t get_current_time_nsec(void) {
|
||||||
|
struct timespec now;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
return timespec_to_nsec(&now);
|
||||||
|
}
|
||||||
|
|
||||||
void timespec_sub(struct timespec *r, const struct timespec *a,
|
void timespec_sub(struct timespec *r, const struct timespec *a,
|
||||||
const struct timespec *b) {
|
const struct timespec *b) {
|
||||||
r->tv_sec = a->tv_sec - b->tv_sec;
|
r->tv_sec = a->tv_sec - b->tv_sec;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue