1919#include < algorithm>
2020#include < cstring>
2121#include < iostream>
22+ #include < mutex>
2223#include < string>
2324#include < thread> // NOLINT
2425#include < vector>
@@ -95,7 +96,7 @@ std::string PathForResource() {
9596 return std::string ();
9697}
9798void 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
99100 // suppressed.
100101 static const int kLineBufferSize = 1024 ;
101102 char buffer[kLineBufferSize + 2 ];
@@ -122,20 +123,27 @@ void LogMessage(const char* format, ...) {
122123
123124static bool g_save_full_log = false ;
124125static std::vector<std::string> g_full_logs; // NOLINT
126+ static std::mutex g_full_log_mutex;
125127
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)); }
127131
128132bool GetPreserveFullLog () { return g_save_full_log; }
129133void SetPreserveFullLog (bool b) { g_save_full_log = b; }
130134
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+ }
132139
133140void OutputFullLog () {
141+ std::lock_guard<std::mutex> guard (g_full_log_mutex);
134142 for (int i = 0 ; i < g_full_logs.size (); ++i) {
135143 fputs (g_full_logs[i].c_str (), stdout);
136144 }
137145 fflush (stdout);
138- ClearFullLog ();
146+ g_full_logs. clear ();
139147}
140148
141149WindowContext GetWindowContext () { return nullptr ; }
0 commit comments