This commit is contained in:
Kovid Goyal 2019-12-08 22:37:47 +05:30
parent e3e02c7271
commit 7bf0afa621
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 35 additions and 17 deletions

1
glfw/init.c vendored
View File

@ -27,7 +27,6 @@
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#define MONOTONIC_START_MODULE
#include "internal.h"
#include "mappings.h"

10
glfw/monotonic.c vendored Normal file
View File

@ -0,0 +1,10 @@
/*
* monotonic.c
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#define _POSIX_C_SOURCE 200809L
#define MONOTONIC_IMPLEMENTATION
#include "../kitty/monotonic.h"

View File

@ -31,6 +31,7 @@
"input.c",
"monitor.c",
"vulkan.c",
"monotonic.c",
"window.c"
]
},

View File

@ -5,7 +5,6 @@
* Distributed under terms of the GPL3 license.
*/
#define MONOTONIC_START_MODULE
#ifdef __APPLE__
// Needed for _CS_DARWIN_USER_CACHE_DIR
#define _DARWIN_C_SOURCE

10
kitty/monotonic.c Normal file
View File

@ -0,0 +1,10 @@
/*
* monotonic.c
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#define _POSIX_C_SOURCE 200809L
#define MONOTONIC_IMPLEMENTATION
#include "monotonic.h"

View File

@ -61,14 +61,21 @@ static inline double monotonic_t_to_s_double(monotonic_t time) {
return (double)time / 1000.0 / 1000.0 / 1000.0;
}
#ifdef MONOTONIC_START_MODULE
monotonic_t monotonic_start_time = 0;
#else
extern monotonic_t monotonic_start_time;
#endif
extern monotonic_t monotonic_(void);
static inline monotonic_t monotonic(void) {
return monotonic_() - monotonic_start_time;
}
static inline monotonic_t monotonic_(void) {
static inline void init_monotonic(void) {
monotonic_start_time = monotonic_();
}
#ifdef MONOTONIC_IMPLEMENTATION
monotonic_t monotonic_start_time = 0;
monotonic_t monotonic_(void) {
struct timespec ts = {0};
#ifdef CLOCK_HIGHRES
clock_gettime(CLOCK_HIGHRES, &ts);
@ -79,11 +86,4 @@ static inline monotonic_t monotonic_(void) {
#endif
return calc_nano_time(ts);
}
static inline monotonic_t monotonic(void) {
return monotonic_() - monotonic_start_time;
}
static inline void init_monotonic(void) {
monotonic_start_time = monotonic_();
}
#endif

View File

@ -212,10 +212,9 @@ def init_env(
cppflags = shlex.split(cppflags)
for el in extra_logging:
cppflags.append('-DDEBUG_{}'.format(el.upper().replace('-', '_')))
# _POSIX_C_SOURCE is needed for clock_gettime() in monotonic.h
cflags = os.environ.get(
'OVERRIDE_CFLAGS', (
'-Wextra {} -Wno-missing-field-initializers -Wall -Wstrict-prototypes -D_POSIX_C_SOURCE=200809L -std=c11'
'-Wextra {} -Wno-missing-field-initializers -Wall -Wstrict-prototypes -std=c11'
' -pedantic-errors -Werror {} {} -fwrapv {} {} -pipe {} -fvisibility=hidden'
).format(
float_conversion,