Skip to content

Commit 4ff479c

Browse files
committed
fixup: dont use static pointer in header
Defining the global pointer static results in the C++ compiler creating a separate pointer for every translation unit, the definition is included in. I'm pretty sure it's not what you want and it's the cause of your problems.
1 parent 19b4838 commit 4ff479c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ endif()
5454
add_library(
5555
codspeed
5656
src/codspeed.cpp
57+
src/measurement.cpp
5758
src/walltime.cpp
5859
src/uri.cpp
5960
src/workspace.cpp

core/include/measurement.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ extern "C" {
1515
#include "core.h"
1616
}
1717

18-
static InstrumentHooks* g_hooks = nullptr;
18+
extern InstrumentHooks* g_hooks;
1919

20-
inline void measurement_init() {
21-
if (!g_hooks) {
22-
g_hooks = instrument_hooks_init();
23-
}
24-
}
20+
void measurement_init();
2521

2622
inline std::string get_version() {
2723
#ifdef CODSPEED_VERSION

core/src/measurement.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "measurement.hpp"
2+
3+
InstrumentHooks* g_hooks = nullptr;
4+
5+
void measurement_init() {
6+
if (!g_hooks) {
7+
g_hooks = instrument_hooks_init();
8+
}
9+
}

0 commit comments

Comments
 (0)