diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-02-02 08:58:20 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-02-02 08:58:20 +0200 |
commit | 1c899adcdd4a1a3baa0a554932f0b2b40ae809b8 (patch) | |
tree | c8a516f1e06924420a2f03a4ae81a1d25692bd28 /libbutl/diagnostics.cxx | |
parent | 23c07078a9f2790b96a6ee6a6183911aaec71533 (diff) |
Move diag_frame to libbutl
Diffstat (limited to 'libbutl/diagnostics.cxx')
-rw-r--r-- | libbutl/diagnostics.cxx | 32 |
1 files changed, 29 insertions, 3 deletions
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 <cstddef> // size_t #include <iostream> // cerr +#include <libbutl/ft/lang.hxx> // thread_local + #include <libbutl/utility.hxx> #include <libbutl/optional.hxx> #include <libbutl/fdstream.hxx> @@ -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; + } } |