1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

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 <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2025-01-09 01:22:49 -05:00
parent a9b07d7684
commit 82f1fd8054
5 changed files with 20 additions and 18 deletions

View File

@ -117,7 +117,7 @@ namespace crucible {
while (full() || locked(name)) { while (full() || locked(name)) {
m_condvar.wait(lock); 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); THROW_CHECK0(runtime_error, rv.second);
} }
@ -129,7 +129,7 @@ namespace crucible {
if (full() || locked(name)) { if (full() || locked(name)) {
return false; 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); THROW_CHECK1(runtime_error, name, rv.second);
return true; return true;
} }

View File

@ -10,6 +10,10 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
extern "C" {
pid_t gettid() throw();
};
namespace crucible { namespace crucible {
using namespace std; using namespace std;
@ -73,7 +77,6 @@ namespace crucible {
typedef ResourceHandle<Process::id, Process> Pid; typedef ResourceHandle<Process::id, Process> Pid;
pid_t gettid();
double getloadavg1(); double getloadavg1();
double getloadavg5(); double getloadavg5();
double getloadavg15(); double getloadavg15();

View File

@ -76,7 +76,7 @@ namespace crucible {
DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ltm)); DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ltm));
header_stream << buf; header_stream << buf;
header_stream << " " << getpid() << "." << crucible::gettid(); header_stream << " " << getpid() << "." << gettid();
if (add_prefix_level) { if (add_prefix_level) {
header_stream << "<" << m_loglevel << ">"; header_stream << "<" << m_loglevel << ">";
} }
@ -88,7 +88,7 @@ namespace crucible {
header_stream << "<" << m_loglevel << ">"; header_stream << "<" << m_loglevel << ">";
} }
header_stream << (m_name.empty() ? "thread" : m_name); header_stream << (m_name.empty() ? "thread" : m_name);
header_stream << "[" << crucible::gettid() << "]"; header_stream << "[" << gettid() << "]";
} }
header_stream << ": "; header_stream << ": ";

View File

@ -7,13 +7,18 @@
#include <cstdlib> #include <cstdlib>
#include <utility> #include <utility>
// for gettid()
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
extern "C" {
pid_t
__attribute__((weak))
gettid() throw()
{
return syscall(SYS_gettid);
}
};
namespace crucible { namespace crucible {
using namespace std; using namespace std;
@ -111,12 +116,6 @@ namespace crucible {
} }
} }
pid_t
gettid()
{
return syscall(SYS_gettid);
}
double double
getloadavg1() getloadavg1()
{ {

View File

@ -91,9 +91,9 @@ BeesNote::~BeesNote()
tl_next = m_prev; tl_next = m_prev;
unique_lock<mutex> lock(s_mutex); unique_lock<mutex> lock(s_mutex);
if (tl_next) { if (tl_next) {
s_status[crucible::gettid()] = tl_next; s_status[gettid()] = tl_next;
} else { } else {
s_status.erase(crucible::gettid()); s_status.erase(gettid());
} }
} }
@ -104,7 +104,7 @@ BeesNote::BeesNote(function<void(ostream &os)> f) :
m_prev = tl_next; m_prev = tl_next;
tl_next = this; tl_next = this;
unique_lock<mutex> lock(s_mutex); unique_lock<mutex> lock(s_mutex);
s_status[crucible::gettid()] = tl_next; s_status[gettid()] = tl_next;
} }
void void