From 1c899adcdd4a1a3baa0a554932f0b2b40ae809b8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Feb 2022 08:58:20 +0200 Subject: Move diag_frame to libbutl --- libbutl/diagnostics.cxx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'libbutl/diagnostics.cxx') diff --git a/libbutl/diagnostics.cxx b/libbutl/diagnostics.cxx index 8525d60..0826375 100644 --- a/libbutl/diagnostics.cxx +++ b/libbutl/diagnostics.cxx @@ -17,6 +17,8 @@ #include // size_t #include // cerr +#include // thread_local + #include #include #include @@ -131,14 +133,14 @@ namespace butl default_writer (const diag_record& r) { r.os.put ('\n'); - diag_stream_lock () << r.os.str (); + + diag_stream_lock l; + (*diag_stream) << r.os.str (); // We can endup flushing the result of several writes. The last one may // possibly be incomplete, but that's not a problem as it will also be // followed by the flush() call. // - // @@ Strange: why not just hold the lock for both write and flush? - // diag_stream->flush (); } @@ -186,4 +188,28 @@ namespace butl flush (); #endif } + + // Diagnostics stack. + // + static +#ifdef __cpp_thread_local + thread_local +#else + __thread +#endif + const diag_frame* diag_frame_stack = nullptr; + + const diag_frame* diag_frame:: + stack () noexcept + { + return diag_frame_stack; + } + + const diag_frame* diag_frame:: + stack (const diag_frame* f) noexcept + { + const diag_frame* r (diag_frame_stack); + diag_frame_stack = f; + return r; + } } -- cgit v1.1