Skip to content

Commit e84fbe2

Browse files
committed
removed global state
1 parent 6cfaf55 commit e84fbe2

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

support/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(SOURCES
1717
ppTiming.cpp
1818
ppAssert.cpp
1919
ViewComm.cpp
20+
ppPrint.cpp
2021
)
2122

2223
add_library(support ${SOURCES})

support/ppPrint.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "ppPrint.h"
2+
3+
namespace pumipic {
4+
5+
FILE* pp_stdout = stdout;
6+
FILE* pp_stderr = stderr;
7+
8+
FILE* getStdout() { return pp_stdout; }
9+
FILE* getStderr() { return pp_stderr; }
10+
11+
void setStdout(FILE* out) {
12+
assert(out != NULL);
13+
pp_stdout = out;
14+
}
15+
16+
void setStderr(FILE* err) {
17+
assert(err != NULL);
18+
pp_stderr = err;
19+
}
20+
}

support/ppPrint.h

+6-13
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,18 @@ namespace pumipic {
1515
#define ACTIVE_GPU_EXECUTION
1616
#endif
1717

18-
inline FILE* pp_stdout = stdout;
19-
inline FILE* pp_stderr = stderr;
18+
FILE* getStdout();
19+
FILE* getStderr();
2020

21-
inline void setStdout(FILE* out) {
22-
assert(out != NULL);
23-
pp_stdout = out;
24-
}
25-
26-
inline void setStderr(FILE* err) {
27-
assert(err != NULL);
28-
pp_stderr = err;
29-
}
21+
void setStdout(FILE* out);
22+
void setStderr(FILE* err);
3023

3124
template<typename... Args>
3225
void printError(std::string fmt, const Args&... args) {
3326
#if defined(PUMIPIC_SPDLOG_ENABLED) && defined(PUMIPIC_PRINT_ENABLED)
3427
spdlog::error("{}", fmt::sprintf(fmt, args...));
3528
#elif defined(PUMIPIC_PRINT_ENABLED)
36-
fprintf(pp_stderr, ("[ERROR]"+fmt).c_str(), args...);
29+
fprintf(getStderr(), ("[ERROR]"+fmt).c_str(), args...);
3730
#endif
3831
}
3932

@@ -43,7 +36,7 @@ namespace pumipic {
4336
#if defined(PUMIPIC_SPDLOG_ENABLED) && defined(PUMIPIC_PRINT_ENABLED) && !defined(ACTIVE_GPU_EXECUTION)
4437
spdlog::info("{}", fmt::sprintf(fmt, args...));
4538
#elif defined(PUMIPIC_PRINT_ENABLED) && !defined(ACTIVE_GPU_EXECUTION)
46-
fprintf(pp_stdout, fmt, args...);
39+
fprintf(getStdout(), fmt, args...);
4740
#endif
4841
}
4942

0 commit comments

Comments
 (0)