From 82f1fd8054364fd638c95e4e6a0f9e887bcb69bd Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Thu, 9 Jan 2025 01:22:49 -0500 Subject: [PATCH] process: replace crucible::gettid() with a weak symbol Since we're now using weak symbols for dodgy libc functions, we might as well do it for gettid() too. Use the ::gettid() global namespace and let libc override it. Signed-off-by: Zygo Blaxell --- include/crucible/lockset.h | 4 ++-- include/crucible/process.h | 5 ++++- lib/chatter.cc | 4 ++-- lib/process.cc | 19 +++++++++---------- src/bees-trace.cc | 6 +++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/crucible/lockset.h b/include/crucible/lockset.h index 6b53cf4..98a107d 100644 --- a/include/crucible/lockset.h +++ b/include/crucible/lockset.h @@ -117,7 +117,7 @@ namespace crucible { while (full() || locked(name)) { m_condvar.wait(lock); } - auto rv = m_set.insert(make_pair(name, crucible::gettid())); + auto rv = m_set.insert(make_pair(name, gettid())); THROW_CHECK0(runtime_error, rv.second); } @@ -129,7 +129,7 @@ namespace crucible { if (full() || locked(name)) { return false; } - auto rv = m_set.insert(make_pair(name, crucible::gettid())); + auto rv = m_set.insert(make_pair(name, gettid())); THROW_CHECK1(runtime_error, name, rv.second); return true; } diff --git a/include/crucible/process.h b/include/crucible/process.h index 52549b2..845ab27 100644 --- a/include/crucible/process.h +++ b/include/crucible/process.h @@ -10,6 +10,10 @@ #include #include +extern "C" { + pid_t gettid() throw(); +}; + namespace crucible { using namespace std; @@ -73,7 +77,6 @@ namespace crucible { typedef ResourceHandle Pid; - pid_t gettid(); double getloadavg1(); double getloadavg5(); double getloadavg15(); diff --git a/lib/chatter.cc b/lib/chatter.cc index efa17af..56cee51 100644 --- a/lib/chatter.cc +++ b/lib/chatter.cc @@ -76,7 +76,7 @@ namespace crucible { DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", <m)); header_stream << buf; - header_stream << " " << getpid() << "." << crucible::gettid(); + header_stream << " " << getpid() << "." << gettid(); if (add_prefix_level) { header_stream << "<" << m_loglevel << ">"; } @@ -88,7 +88,7 @@ namespace crucible { header_stream << "<" << m_loglevel << ">"; } header_stream << (m_name.empty() ? "thread" : m_name); - header_stream << "[" << crucible::gettid() << "]"; + header_stream << "[" << gettid() << "]"; } header_stream << ": "; diff --git a/lib/process.cc b/lib/process.cc index b838cdd..808073e 100644 --- a/lib/process.cc +++ b/lib/process.cc @@ -7,13 +7,18 @@ #include #include -// for gettid() -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include #include +extern "C" { + pid_t + __attribute__((weak)) + gettid() throw() + { + return syscall(SYS_gettid); + } +}; + namespace crucible { using namespace std; @@ -111,12 +116,6 @@ namespace crucible { } } - pid_t - gettid() - { - return syscall(SYS_gettid); - } - double getloadavg1() { diff --git a/src/bees-trace.cc b/src/bees-trace.cc index d04d4c1..5e58532 100644 --- a/src/bees-trace.cc +++ b/src/bees-trace.cc @@ -91,9 +91,9 @@ BeesNote::~BeesNote() tl_next = m_prev; unique_lock lock(s_mutex); if (tl_next) { - s_status[crucible::gettid()] = tl_next; + s_status[gettid()] = tl_next; } else { - s_status.erase(crucible::gettid()); + s_status.erase(gettid()); } } @@ -104,7 +104,7 @@ BeesNote::BeesNote(function f) : m_prev = tl_next; tl_next = this; unique_lock lock(s_mutex); - s_status[crucible::gettid()] = tl_next; + s_status[gettid()] = tl_next; } void