From 5b9a463db890e86b95c7ac37484704759eabc641 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 24 Oct 2012 16:45:53 +0100 Subject: [PATCH] Use compiler TLS for thread_id tracking. --- common/trace_writer_local.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp index 5aeedac..feb5c91 100644 --- a/common/trace_writer_local.cpp +++ b/common/trace_writer_local.cpp @@ -128,8 +128,8 @@ LocalWriter::open(void) { #endif } -static unsigned next_thread_id = 0; -static os::thread_specific_ptr thread_id_specific_ptr; +static unsigned next_thread_num = 1; +static thread_specific unsigned thread_num = 0; unsigned LocalWriter::beginEnter(const FunctionSig *sig) { mutex.lock(); @@ -139,17 +139,13 @@ unsigned LocalWriter::beginEnter(const FunctionSig *sig) { open(); } - unsigned *thread_id_ptr = thread_id_specific_ptr.get(); - unsigned thread_id; - if (thread_id_ptr) { - thread_id = *thread_id_ptr; - } else { - thread_id = next_thread_id++; - thread_id_ptr = new unsigned; - *thread_id_ptr = thread_id; - thread_id_specific_ptr.reset(thread_id_ptr); + unsigned this_thread_num = thread_num; + if (!this_thread_num) { + this_thread_num = thread_num = next_thread_num++; } + assert(thread_num > 0); + unsigned thread_id = thread_num - 1; return Writer::beginEnter(sig, thread_id); } -- 2.43.0