forked from alpha0010/ClangLib
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcclogger.h
177 lines (158 loc) · 8.18 KB
/
cclogger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
* http://www.gnu.org/licenses/gpl-3.0.html
*/
#ifndef CCLOGGER_H
#define CCLOGGER_H
#include <wx/string.h>
#include <wx/thread.h>
#include <memory> // auto_ptr
#include <cbexception.h> // cbAssert
#include <logmanager.h> // F()
#include <prep.h> // nullptr
class wxEvtHandler;
#ifndef CC_PROCESS_LOG_EVENT_TO_PARENT
#define CC_PROCESS_LOG_EVENT_TO_PARENT 0
#endif
#ifdef CC_PARSER_TEST
#undef CC_PROCESS_LOG_EVENT_TO_PARENT
#define CC_PROCESS_LOG_EVENT_TO_PARENT 1
#endif
extern bool g_EnableDebugTrace; //!< Toggles tracing into file.
extern const wxString g_DebugTraceFile; //!< Trace file name (if above is enabled).
extern long g_idCCAddToken;
extern long g_idCCLogger;
extern long g_idCCDebugLogger;
class CCLogger
{
public:
static CCLogger* Get();
void Init(wxEvtHandler* parent, int logId, int debugLogId, int addTokenId = -1);
void AddToken(const wxString& msg);
void Log(const wxString& msg);
void DebugLog(const wxString& msg);
protected:
CCLogger();
virtual ~CCLogger() { ; }
CCLogger(const CCLogger&) { ; }
CCLogger& operator=(const CCLogger&) { return *this; }
// static member variables (instance and critical section for Parser)
friend class std::auto_ptr<CCLogger>;
static std::auto_ptr<CCLogger> s_Inst;
private:
wxEvtHandler* m_Parent;
int m_LogId;
int m_DebugLogId;
int m_AddTokenId;
};
// For tracking, either uncomment:
//#define CC_ENABLE_LOCKER_TRACK
// ...or:
#define CC_ENABLE_LOCKER_ASSERT
// ..or none of the above.
#if defined(CC_ENABLE_LOCKER_TRACK)
// TRACKING MUTXES
// [1] Implementations for tracking mutexes:
#define THREAD_LOCKER_MTX_LOCK(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Lock() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
#define THREAD_LOCKER_MTX_LOCK_SUCCESS(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Lock().Success() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
#define THREAD_LOCKER_MTX_UNLOCK(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Unlock() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
#define THREAD_LOCKER_MTX_UNLOCK_SUCCESS(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Unlock().Success() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
#define THREAD_LOCKER_MTX_FAIL(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Fail() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
// [2] Cumulative convenient macros for tracking mutexes [USE THESE!]:
#define CC_LOCKER_TRACK_TT_MTX_LOCK(M) \
{ \
THREAD_LOCKER_MTX_LOCK(M); \
if (M.Lock()==wxMUTEX_NO_ERROR) \
THREAD_LOCKER_MTX_LOCK_SUCCESS(M); \
else \
THREAD_LOCKER_MTX_FAIL(M); \
}
#define CC_LOCKER_TRACK_TT_MTX_UNLOCK(M) \
{ \
THREAD_LOCKER_MTX_UNLOCK(M); \
if (M.Unlock()==wxMUTEX_NO_ERROR) \
THREAD_LOCKER_MTX_UNLOCK_SUCCESS(M); \
else \
THREAD_LOCKER_MTX_FAIL(M); \
}
#define CC_LOCKER_TRACK_CBBT_MTX_LOCK CC_LOCKER_TRACK_TT_MTX_LOCK
#define CC_LOCKER_TRACK_CBBT_MTX_UNLOCK CC_LOCKER_TRACK_TT_MTX_UNLOCK
#define CC_LOCKER_TRACK_P_MTX_LOCK CC_LOCKER_TRACK_TT_MTX_LOCK
#define CC_LOCKER_TRACK_P_MTX_UNLOCK CC_LOCKER_TRACK_TT_MTX_UNLOCK
// TRACKING CRITICAL SECIONS
// [2] Implementations for tracking critical sections:
#define THREAD_LOCKER_CS_ENTER(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Enter() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
#define THREAD_LOCKER_CS_ENTERED(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Entered() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
#define THREAD_LOCKER_CS_LEAVE(NAME) \
CCLogger::Get()->DebugLog(F(_T("%s.Leave() : %s(), %s, %d"), \
wxString(#NAME, wxConvUTF8).wx_str(), \
wxString(__FUNCTION__, wxConvUTF8).wx_str(), \
wxString(__FILE__, wxConvUTF8).wx_str(), \
__LINE__))
// [2] Cumulative convenient macros for tracking critical sections [USE THESE!]:
#define CC_LOCKER_TRACK_CS_ENTER(CS) \
{ \
THREAD_LOCKER_CS_ENTER(CS); \
CS.Enter(); \
THREAD_LOCKER_CS_ENTERED(CS); \
}
#define CC_LOCKER_TRACK_CS_LEAVE(CS) \
{ \
THREAD_LOCKER_CS_LEAVE(CS); \
CS.Leave(); \
}
#elif defined CC_ENABLE_LOCKER_ASSERT
#define CC_LOCKER_TRACK_CS_ENTER(CS) CS.Enter();
#define CC_LOCKER_TRACK_CS_LEAVE(CS) CS.Leave();
#define CC_LOCKER_TRACK_TT_MTX_LOCK(M) cbAssert(M.Lock()==wxMUTEX_NO_ERROR);
#define CC_LOCKER_TRACK_TT_MTX_UNLOCK(M) cbAssert(M.Unlock()==wxMUTEX_NO_ERROR);
#define CC_LOCKER_TRACK_CBBT_MTX_LOCK CC_LOCKER_TRACK_TT_MTX_LOCK
#define CC_LOCKER_TRACK_CBBT_MTX_UNLOCK CC_LOCKER_TRACK_TT_MTX_UNLOCK
#define CC_LOCKER_TRACK_P_MTX_LOCK CC_LOCKER_TRACK_TT_MTX_LOCK
#define CC_LOCKER_TRACK_P_MTX_UNLOCK CC_LOCKER_TRACK_TT_MTX_UNLOCK
#else
#define CC_LOCKER_TRACK_CS_ENTER(CS) CS.Enter();
#define CC_LOCKER_TRACK_CS_LEAVE(CS) CS.Leave();
#define CC_LOCKER_TRACK_TT_MTX_LOCK(M) M.Lock();
#define CC_LOCKER_TRACK_TT_MTX_UNLOCK(M) M.Unlock();
#define CC_LOCKER_TRACK_CBBT_MTX_LOCK CC_LOCKER_TRACK_TT_MTX_LOCK
#define CC_LOCKER_TRACK_CBBT_MTX_UNLOCK CC_LOCKER_TRACK_TT_MTX_UNLOCK
#define CC_LOCKER_TRACK_P_MTX_LOCK CC_LOCKER_TRACK_TT_MTX_LOCK
#define CC_LOCKER_TRACK_P_MTX_UNLOCK CC_LOCKER_TRACK_TT_MTX_UNLOCK
#endif
#endif // CCLOGGER_H