From 5738940535e86bcfb0520342a15971d645e6a54a Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 17 Feb 2021 18:25:45 +0100 Subject: [PATCH] Replace my_gettid with libosmocore osmo_gettid API The API was moved to libosmocore, let's use it instead of defining our own here with all the complexity in build system involved. Depends: libosmocore.git Change-Id Id7534beeb22fcd50813dab76dd68818e2ff87ec2 Related: OS#5027 Change-Id: I19e32fbc47bd88a668e0c912e89b001b0f8831dd --- CommonLibs/Threads.cpp | 4 +++- CommonLibs/debug.c | 24 ------------------------ CommonLibs/debug.h | 8 +++----- TODO-RELEASE | 1 + configure.ac | 9 --------- 5 files changed, 7 insertions(+), 39 deletions(-) diff --git a/CommonLibs/Threads.cpp b/CommonLibs/Threads.cpp index d8dab579..b3ff52f0 100644 --- a/CommonLibs/Threads.cpp +++ b/CommonLibs/Threads.cpp @@ -32,6 +32,8 @@ #include "Timeval.h" #include "Logger.h" +#include + using namespace std; #ifndef HAVE_ATOMIC_OPS @@ -108,7 +110,7 @@ void Signal::wait(Mutex& wMutex, unsigned timeout) const void set_selfthread_name(const char *name) { pthread_t selfid = pthread_self(); - pid_t tid = my_gettid(); + pid_t tid = osmo_gettid(); if (pthread_setname_np(selfid, name) == 0) { LOG(INFO) << "Thread "<< selfid << " (task " << tid << ") set name: " << name; } else { diff --git a/CommonLibs/debug.c b/CommonLibs/debug.c index 7ee81841..08954f5f 100644 --- a/CommonLibs/debug.c +++ b/CommonLibs/debug.c @@ -21,18 +21,6 @@ * See the COPYING file in the main directory for details. */ -#include "config.h" - -/* If HAVE_GETTID, then "_GNU_SOURCE" may need to be defined to use gettid() */ -#if HAVE_GETTID -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include "config.h" - #include #include #include "debug.h" @@ -93,15 +81,3 @@ const struct log_info log_info = { .cat = default_categories, .num_cat = ARRAY_SIZE(default_categories), }; - -pid_t my_gettid(void) -{ -#if HAVE_GETTID - return gettid(); -#elif defined(LINUX) && defined(__NR_gettid) - return (pid_t) syscall(__NR_gettid); -#else - #pragma message ("use pid as tid") - return getpid(); -#endif -} diff --git a/CommonLibs/debug.h b/CommonLibs/debug.h index dd781682..ddb5c750 100644 --- a/CommonLibs/debug.h +++ b/CommonLibs/debug.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include +#include extern const struct log_info log_info; @@ -19,12 +19,10 @@ enum { DCTR, }; -pid_t my_gettid(void); - #define CLOGC(category, level, fmt, args...) do { \ - LOGP(category, level, "[tid=%ld] " fmt, (long int) my_gettid(), ##args); \ + LOGP(category, level, "[tid=%ld] " fmt, (long int) osmo_gettid(), ##args); \ } while(0) #define CLOGCHAN(chan, category, level, fmt, args...) do { \ - LOGP(category, level, "[tid=%ld][chan=%zu] " fmt, (long int) my_gettid(), chan, ##args); \ + LOGP(category, level, "[tid=%ld][chan=%zu] " fmt, (long int) osmo_gettid(), chan, ##args); \ } while(0) diff --git a/TODO-RELEASE b/TODO-RELEASE index 84ecf22c..c916fb1c 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -1,3 +1,4 @@ * update libosmocore dependency to > 1.3.x for osmo_sched_vty_init(), osmo_sched_vty_apply_localthread() * update osmo-gsm-manuals dependency to > 0.3.0 for vty_cpu_sched.adoc include. * update libosmocore dependency to > 1.4.x for osmo_fd_{read,write}_{enable,disable}() +* update libosmocore dependency to > 1.4.2 for osmo_gettid() diff --git a/configure.ac b/configure.ac index 7f6aef7a..8067fa74 100644 --- a/configure.ac +++ b/configure.ac @@ -82,15 +82,6 @@ AC_TYPE_SIZE_T AC_HEADER_TIME AC_C_BIGENDIAN -# Check if gettid is available (despite not being documented in glibc doc, it requires __USE_GNU on some systems) -# C compiler is used since __USE_GNU seems to be always defined for g++. -save_CPPFLAGS=$CPPFLAGS -AC_LANG_PUSH(C) -CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" -AC_CHECK_FUNCS([gettid]) -AC_LANG_POP(C) -CPPFLAGS=$save_CPPFLAGS - PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.3.0) PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.3.0) PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.3.0)