Skip to content

Commit 7bf0afa

Browse files
committed
Fix #2187
1 parent e3e02c7 commit 7bf0afa

File tree

7 files changed

+35
-17
lines changed

7 files changed

+35
-17
lines changed

glfw/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
// Please use C89 style variable declarations in this file because VS 2010
2828
//========================================================================
2929

30-
#define MONOTONIC_START_MODULE
3130
#include "internal.h"
3231
#include "mappings.h"
3332

glfw/monotonic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* monotonic.c
3+
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
4+
*
5+
* Distributed under terms of the GPL3 license.
6+
*/
7+
8+
#define _POSIX_C_SOURCE 200809L
9+
#define MONOTONIC_IMPLEMENTATION
10+
#include "../kitty/monotonic.h"

glfw/source-info.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"input.c",
3232
"monitor.c",
3333
"vulkan.c",
34+
"monotonic.c",
3435
"window.c"
3536
]
3637
},

kitty/data-types.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Distributed under terms of the GPL3 license.
66
*/
77

8-
#define MONOTONIC_START_MODULE
98
#ifdef __APPLE__
109
// Needed for _CS_DARWIN_USER_CACHE_DIR
1110
#define _DARWIN_C_SOURCE

kitty/monotonic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* monotonic.c
3+
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
4+
*
5+
* Distributed under terms of the GPL3 license.
6+
*/
7+
8+
#define _POSIX_C_SOURCE 200809L
9+
#define MONOTONIC_IMPLEMENTATION
10+
#include "monotonic.h"

kitty/monotonic.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,21 @@ static inline double monotonic_t_to_s_double(monotonic_t time) {
6161
return (double)time / 1000.0 / 1000.0 / 1000.0;
6262
}
6363

64-
#ifdef MONOTONIC_START_MODULE
65-
monotonic_t monotonic_start_time = 0;
66-
#else
6764
extern monotonic_t monotonic_start_time;
68-
#endif
65+
extern monotonic_t monotonic_(void);
6966

67+
static inline monotonic_t monotonic(void) {
68+
return monotonic_() - monotonic_start_time;
69+
}
7070

71-
static inline monotonic_t monotonic_(void) {
71+
static inline void init_monotonic(void) {
72+
monotonic_start_time = monotonic_();
73+
}
74+
75+
#ifdef MONOTONIC_IMPLEMENTATION
76+
monotonic_t monotonic_start_time = 0;
77+
78+
monotonic_t monotonic_(void) {
7279
struct timespec ts = {0};
7380
#ifdef CLOCK_HIGHRES
7481
clock_gettime(CLOCK_HIGHRES, &ts);
@@ -79,11 +86,4 @@ static inline monotonic_t monotonic_(void) {
7986
#endif
8087
return calc_nano_time(ts);
8188
}
82-
83-
static inline monotonic_t monotonic(void) {
84-
return monotonic_() - monotonic_start_time;
85-
}
86-
87-
static inline void init_monotonic(void) {
88-
monotonic_start_time = monotonic_();
89-
}
89+
#endif

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ def init_env(
212212
cppflags = shlex.split(cppflags)
213213
for el in extra_logging:
214214
cppflags.append('-DDEBUG_{}'.format(el.upper().replace('-', '_')))
215-
# _POSIX_C_SOURCE is needed for clock_gettime() in monotonic.h
216215
cflags = os.environ.get(
217216
'OVERRIDE_CFLAGS', (
218-
'-Wextra {} -Wno-missing-field-initializers -Wall -Wstrict-prototypes -D_POSIX_C_SOURCE=200809L -std=c11'
217+
'-Wextra {} -Wno-missing-field-initializers -Wall -Wstrict-prototypes -std=c11'
219218
' -pedantic-errors -Werror {} {} -fwrapv {} {} -pipe {} -fvisibility=hidden'
220219
).format(
221220
float_conversion,

0 commit comments

Comments
 (0)