From c62b1b47b4fc0cbd8fe1c140e0634cc522d58ed5 Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Wed, 13 May 2020 00:12:21 +0100 Subject: [PATCH] _backend_worker_thread_id doesn't need to be atomic --- quill/include/quill/detail/BackendWorker.h | 12 ++++++------ quill/src/detail/BackendWorker.cpp | 4 +--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/quill/include/quill/detail/BackendWorker.h b/quill/include/quill/detail/BackendWorker.h index 5b9d2205..6ff551b7 100644 --- a/quill/include/quill/detail/BackendWorker.h +++ b/quill/include/quill/detail/BackendWorker.h @@ -164,7 +164,7 @@ class BackendWorker HandlerCollection const& _handler_collection; std::thread _backend_worker_thread; /** the backend thread that is writing the log to the handlers */ - std::atomic _backend_worker_thread_id; /** cached backend worker thread id */ + uint32_t _backend_worker_thread_id; /** cached backend worker thread id */ std::unique_ptr _rdtsc_clock{nullptr}; /** rdtsc clock if enabled **/ @@ -220,13 +220,13 @@ void BackendWorker::run() #endif // Cache this thread's id - _backend_worker_thread_id.store(get_thread_id(), std::memory_order_relaxed); + _backend_worker_thread_id = get_thread_id(); - // All okay, set the backend worker thread status - _is_running.store(true, std::memory_order_relaxed); + // All okay, set the backend worker thread running flag + _is_running.store(true, std::memory_order_seq_cst); // Running - while (QUILL_LIKELY(is_running())) + while (QUILL_LIKELY(_is_running.load(std::memory_order_relaxed))) { // main loop QUILL_TRY { _main_loop(); } @@ -253,7 +253,7 @@ void BackendWorker::run() // Move the worker ownership to our class _backend_worker_thread.swap(worker); - while (!is_running()) + while (!_is_running.load(std::memory_order_seq_cst)) { // wait for the thread to start std::this_thread::sleep_for(std::chrono::microseconds{100}); diff --git a/quill/src/detail/BackendWorker.cpp b/quill/src/detail/BackendWorker.cpp index 3d34fdc7..e60e5f92 100644 --- a/quill/src/detail/BackendWorker.cpp +++ b/quill/src/detail/BackendWorker.cpp @@ -43,9 +43,7 @@ void BackendWorker::stop() noexcept /***/ uint32_t BackendWorker::thread_id() const noexcept -{ - return _backend_worker_thread_id.load(std::memory_order_relaxed); -} +{ return _backend_worker_thread_id; } #if !defined(QUILL_NO_EXCEPTIONS) /***/