summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/assert.cpp3
-rw-r--r--src/common/logging/backend.cpp17
-rw-r--r--src/common/logging/backend.h3
3 files changed, 23 insertions, 0 deletions
diff --git a/src/common/assert.cpp b/src/common/assert.cpp
index 6026b7dc2..e2c2cade3 100644
--- a/src/common/assert.cpp
+++ b/src/common/assert.cpp
@@ -3,16 +3,19 @@
3 3
4#include "common/assert.h" 4#include "common/assert.h"
5#include "common/common_funcs.h" 5#include "common/common_funcs.h"
6#include "common/logging/backend.h"
6 7
7#include "common/settings.h" 8#include "common/settings.h"
8 9
9void assert_fail_impl() { 10void assert_fail_impl() {
10 if (Settings::values.use_debug_asserts) { 11 if (Settings::values.use_debug_asserts) {
12 Common::Log::Stop();
11 Crash(); 13 Crash();
12 } 14 }
13} 15}
14 16
15[[noreturn]] void unreachable_impl() { 17[[noreturn]] void unreachable_impl() {
18 Common::Log::Stop();
16 Crash(); 19 Crash();
17 throw std::runtime_error("Unreachable code"); 20 throw std::runtime_error("Unreachable code");
18} 21}
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index d4f27197c..7a267f8c0 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -208,6 +208,10 @@ public:
208 instance->StartBackendThread(); 208 instance->StartBackendThread();
209 } 209 }
210 210
211 static void Stop() {
212 instance->StopBackendThread();
213 }
214
211 Impl(const Impl&) = delete; 215 Impl(const Impl&) = delete;
212 Impl& operator=(const Impl&) = delete; 216 Impl& operator=(const Impl&) = delete;
213 217
@@ -259,6 +263,15 @@ private:
259 }); 263 });
260 } 264 }
261 265
266 void StopBackendThread() {
267 backend_thread.request_stop();
268 if (backend_thread.joinable()) {
269 backend_thread.join();
270 }
271
272 ForEachBackend([](Backend& backend) { backend.Flush(); });
273 }
274
262 Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, 275 Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
263 const char* function, std::string&& message) const { 276 const char* function, std::string&& message) const {
264 using std::chrono::duration_cast; 277 using std::chrono::duration_cast;
@@ -313,6 +326,10 @@ void Start() {
313 Impl::Start(); 326 Impl::Start();
314} 327}
315 328
329void Stop() {
330 Impl::Stop();
331}
332
316void DisableLoggingInTests() { 333void DisableLoggingInTests() {
317 initialization_in_progress_suppress_logging = true; 334 initialization_in_progress_suppress_logging = true;
318} 335}
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index 12e5e2498..2a9926e9e 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -14,6 +14,9 @@ void Initialize();
14 14
15void Start(); 15void Start();
16 16
17/// Explicitly stops the logger thread and flushes the buffers
18void Stop();
19
17void DisableLoggingInTests(); 20void DisableLoggingInTests();
18 21
19/** 22/**