From d931539185751c7a84c2f7719a77bad8c7c4fdc5 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Tue, 1 Nov 2022 09:12:39 +0900 Subject: [PATCH] TSan: Make Thread::cur_time thread local --- iocore/eventsystem/I_Thread.h | 6 +++--- iocore/eventsystem/Thread.cc | 2 +- proxy/logging/Log.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iocore/eventsystem/I_Thread.h b/iocore/eventsystem/I_Thread.h index 910f41c29b9..b458f59a9eb 100644 --- a/iocore/eventsystem/I_Thread.h +++ b/iocore/eventsystem/I_Thread.h @@ -156,8 +156,8 @@ class Thread This gets a cached copy of the time so it is very fast and reasonably accurate. The cached time is updated every time the actual operating system time is fetched which is at least every 10ms and generally more frequently. - @note The cached copy shared among threads which means the cached copy is updated - for all threads if any thread updates it. + + @note The cached copy is thread local which means each thread need to update the cached copy by itself. */ static ink_hrtime get_hrtime(); @@ -177,7 +177,7 @@ class Thread protected: Thread(); - static ink_hrtime cur_time; + static thread_local ink_hrtime cur_time; }; extern Thread *this_thread(); diff --git a/iocore/eventsystem/Thread.cc b/iocore/eventsystem/Thread.cc index 38c6c340908..5bdc5fc765a 100644 --- a/iocore/eventsystem/Thread.cc +++ b/iocore/eventsystem/Thread.cc @@ -34,7 +34,7 @@ // Common Interface impl // /////////////////////////////////////////////// -ink_hrtime Thread::cur_time = ink_get_hrtime_internal(); +thread_local ink_hrtime Thread::cur_time = ink_get_hrtime_internal(); thread_local Thread *Thread::this_thread_ptr; Thread::Thread() diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc index 7b37410e8d1..e8d15e66d04 100644 --- a/proxy/logging/Log.cc +++ b/proxy/logging/Log.cc @@ -1399,7 +1399,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */) // Time to work on periodic events?? // - now = Thread::get_hrtime() / HRTIME_SECOND; + now = Thread::get_hrtime_updated() / HRTIME_SECOND; if (now >= last_time + periodic_tasks_interval) { Debug("log-preproc", "periodic tasks for %" PRId64, (int64_t)now); periodic_tasks(now);