diff options
author | Marco Bubke <marco.bubke@qt.io> | 2024-03-12 12:14:23 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2024-03-18 12:59:47 +0000 |
commit | d632a7c82e251abc35b0313e69861b7c85531698 (patch) | |
tree | fd9e199e17117f1a820803a9d62b8b8e2aee6d4c /src/libs | |
parent | 27cfd2e240322fcdd60257ab52f1a737d6fe2809 (diff) |
Nanotrace: If the process is terminated flush the event queues
That terminate handler is only installed if any event queue is
activated. That is only the case if you compile with a special
option.
Change-Id: I4d8661c0fa11d8bb14b49b7b963471f626b3b950
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/nanotrace/nanotracehr.h | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libs/nanotrace/nanotracehr.h b/src/libs/nanotrace/nanotracehr.h index 9d16b1bb63..f9ff55419e 100644 --- a/src/libs/nanotrace/nanotracehr.h +++ b/src/libs/nanotrace/nanotracehr.h @@ -15,6 +15,7 @@ #include <array> #include <atomic> #include <chrono> +#include <exception> #include <fstream> #include <future> #include <mutex> @@ -436,7 +437,12 @@ class EventQueueTracker using Queue = EventQueue<TraceEvent, Tracing::IsEnabled>; public: - EventQueueTracker() = default; + EventQueueTracker() + { + terminateHandler = std::get_terminate(); + + std::set_terminate([]() { EventQueueTracker::get().terminate(); }); + } EventQueueTracker(const EventQueueTracker &) = delete; EventQueueTracker(EventQueueTracker &&) = delete; EventQueueTracker &operator=(const EventQueueTracker &) = delete; @@ -470,8 +476,25 @@ public: } private: + void terminate() + { + flushAll(); + if (terminateHandler) + terminateHandler(); + } + + void flushAll() + { + std::lock_guard lock{mutex}; + + for (auto queue : queues) + queue->flush(); + } + +private: std::mutex mutex; std::vector<Queue *> queues; + std::terminate_handler terminateHandler = nullptr; }; } // namespace Internal |