Skip to content

Commit

Permalink
gral_time_get_monotonic
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Nov 19, 2023
1 parent 80cfaca commit 670e910
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016-2022 Elias Aebi
Copyright (c) 2016-2023 Elias Aebi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion demos/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static void focus_leave(void *user_data) {
}

static int timer(void *user_data) {
printf("timer\n");
printf("timer %f\n", gral_time_get_monotonic());
return 1;
}

Expand Down
7 changes: 7 additions & 0 deletions gral.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ void gral_file_rename(char const *old_path, char const *new_path);
void gral_directory_iterate(char const *path, void (*callback)(char const *name, void *user_data), void *user_data);


/*=========
TIME
=========*/

double gral_time_get_monotonic(void);


/*==========
AUDIO
==========*/
Expand Down
11 changes: 11 additions & 0 deletions gral_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,17 @@ void gral_directory_iterate(char const *path, void (*callback)(char const *name,
}


/*=========
TIME
=========*/

double gral_time_get_monotonic(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec + ts.tv_nsec / 1e9;
}


/*==========
AUDIO
==========*/
Expand Down
11 changes: 11 additions & 0 deletions gral_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,17 @@ void gral_directory_iterate(char const *path, void (*callback)(char const *name,
}


/*=========
TIME
=========*/

double gral_time_get_monotonic(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec + ts.tv_nsec / 1e9;
}


/*==========
AUDIO
==========*/
Expand Down
18 changes: 18 additions & 0 deletions gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,24 @@ void gral_directory_iterate(char const *path_utf8, void (*callback)(char const *
}


/*=========
TIME
=========*/

static double get_frequency() {
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
return frequency.QuadPart;
}

double gral_time_get_monotonic() {
static const double frequency = get_frequency();
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
return count.QuadPart / frequency;
}


/*==========
AUDIO
==========*/
Expand Down

0 comments on commit 670e910

Please sign in to comment.