From 7bf0afa621ccbce8f3a078f7e921e5f5a456257b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 8 Dec 2019 22:37:47 +0530 Subject: [PATCH] Fix #2187 --- glfw/init.c | 1 - glfw/monotonic.c | 10 ++++++++++ glfw/source-info.json | 1 + kitty/data-types.c | 1 - kitty/monotonic.c | 10 ++++++++++ kitty/monotonic.h | 26 +++++++++++++------------- setup.py | 3 +-- 7 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 glfw/monotonic.c create mode 100644 kitty/monotonic.c diff --git a/glfw/init.c b/glfw/init.c index 332102f5d..6318427c2 100644 --- a/glfw/init.c +++ b/glfw/init.c @@ -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" diff --git a/glfw/monotonic.c b/glfw/monotonic.c new file mode 100644 index 000000000..5d071d843 --- /dev/null +++ b/glfw/monotonic.c @@ -0,0 +1,10 @@ +/* + * monotonic.c + * Copyright (C) 2019 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + +#define _POSIX_C_SOURCE 200809L +#define MONOTONIC_IMPLEMENTATION +#include "../kitty/monotonic.h" diff --git a/glfw/source-info.json b/glfw/source-info.json index 497bb2229..20018ff72 100644 --- a/glfw/source-info.json +++ b/glfw/source-info.json @@ -31,6 +31,7 @@ "input.c", "monitor.c", "vulkan.c", + "monotonic.c", "window.c" ] }, diff --git a/kitty/data-types.c b/kitty/data-types.c index a5f4731b5..98b47b03f 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -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 diff --git a/kitty/monotonic.c b/kitty/monotonic.c new file mode 100644 index 000000000..fd6d43982 --- /dev/null +++ b/kitty/monotonic.c @@ -0,0 +1,10 @@ +/* + * monotonic.c + * Copyright (C) 2019 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + +#define _POSIX_C_SOURCE 200809L +#define MONOTONIC_IMPLEMENTATION +#include "monotonic.h" diff --git a/kitty/monotonic.h b/kitty/monotonic.h index 7be3c11aa..0d2d94ce1 100644 --- a/kitty/monotonic.h +++ b/kitty/monotonic.h @@ -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 diff --git a/setup.py b/setup.py index c60535c0e..938fed538 100755 --- a/setup.py +++ b/setup.py @@ -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,