Debian Codegraph @

src/debug.h

raw symbols SCIP
1 #ifndef DEBUG_H
2 #define DEBUG_H
3
4 // See the Makevars file to see how to compile with various debugging settings.
5
6 #if defined(DEBUG_THREAD)
7 #include "tinycthread.h"
8
9 extern tct_thrd_t __main_thread__;
10 extern tct_thrd_t __background_thread__;
11
12 // This must be called from the main thread so that thread assertions can be
13 // tested later.
14 #define REGISTER_MAIN_THREAD() __main_thread__ = tct_thrd_current();
15 #define REGISTER_BACKGROUND_THREAD() __background_thread__ = tct_thrd_current();
16 #define ASSERT_MAIN_THREAD() assert(tct_thrd_current() == __main_thread__);
17 #define ASSERT_BACKGROUND_THREAD() assert(tct_thrd_current() == __background_thread__);
18
19 #else
20 #define REGISTER_MAIN_THREAD()
21 #define REGISTER_BACKGROUND_THREAD()
22 #define ASSERT_MAIN_THREAD()
23 #define ASSERT_BACKGROUND_THREAD()
24
25 #endif // defined(DEBUG_THREAD)
26
27
28 // ============================================================================
29 // Logging
30 // ============================================================================
31
32 void err_printf(const char *fmt, ...);
33
34 enum LogLevel {
35 LOG_OFF,
36 LOG_ERROR,
37 LOG_WARN,
38 LOG_INFO,
39 LOG_DEBUG
40 };
41
42 extern LogLevel log_level_;
43
44 // This is a macro instead of a function, so that if msg is an expression that
45 // involves constructing a string, the string construction does not need to be
46 // executed when the message is not being logged. If it were a function, the
47 // expression would need to be executed even when the message is not actually
48 // logged.
49 //
50 // Conversion to std::string is done so that msg can be a char* or a
51 // std::string. This method is needed because macros can't be overloaded.
52 #define DEBUG_LOG(msg, level) if (log_level_ >= level) err_printf("%s\n", std::string(msg).c_str());
53
54 #endif