19
19
#include < algorithm>
20
20
#include < cstring>
21
21
#include < iostream>
22
+ #include < mutex>
22
23
#include < string>
23
24
#include < thread> // NOLINT
24
25
#include < vector>
@@ -95,7 +96,7 @@ std::string PathForResource() {
95
96
return std::string ();
96
97
}
97
98
void LogMessageV (bool suppress, const char * format, va_list list) {
98
- // Save the log to the g_full_logs list regardless of whether it should be
99
+ // Save the log to the Full Logs list regardless of whether it should be
99
100
// suppressed.
100
101
static const int kLineBufferSize = 1024 ;
101
102
char buffer[kLineBufferSize + 2 ];
@@ -122,20 +123,27 @@ void LogMessage(const char* format, ...) {
122
123
123
124
static bool g_save_full_log = false ;
124
125
static std::vector<std::string> g_full_logs; // NOLINT
126
+ static std::mutex g_full_log_mutex;
125
127
126
- void AddToFullLog (const char * str) { g_full_logs.push_back (std::string (str)); }
128
+ void AddToFullLog (const char * str) {
129
+ std::lock_guard<std::mutex> guard (g_full_log_mutex);
130
+ g_full_logs.push_back (std::string (str)); }
127
131
128
132
bool GetPreserveFullLog () { return g_save_full_log; }
129
133
void SetPreserveFullLog (bool b) { g_save_full_log = b; }
130
134
131
- void ClearFullLog () { g_full_logs.clear (); }
135
+ void ClearFullLog () {
136
+ std::lock_guard<std::mutex> guard (g_full_log_mutex);
137
+ g_full_logs.clear ();
138
+ }
132
139
133
140
void OutputFullLog () {
141
+ std::lock_guard<std::mutex> guard (g_full_log_mutex);
134
142
for (int i = 0 ; i < g_full_logs.size (); ++i) {
135
143
fputs (g_full_logs[i].c_str (), stdout);
136
144
}
137
145
fflush (stdout);
138
- ClearFullLog ();
146
+ g_full_logs. clear ();
139
147
}
140
148
141
149
WindowContext GetWindowContext () { return nullptr ; }
0 commit comments