Skip to content

Commit

Permalink
_backend_worker_thread_id doesn't need to be atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed May 12, 2020
1 parent 878c98a commit c62b1b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 6 additions & 6 deletions quill/include/quill/detail/BackendWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> _backend_worker_thread_id; /** cached backend worker thread id */
uint32_t _backend_worker_thread_id; /** cached backend worker thread id */

std::unique_ptr<RdtscClock> _rdtsc_clock{nullptr}; /** rdtsc clock if enabled **/

Expand Down Expand Up @@ -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(); }
Expand All @@ -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});
Expand Down
4 changes: 1 addition & 3 deletions quill/src/detail/BackendWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/***/
Expand Down

0 comments on commit c62b1b4

Please sign in to comment.