This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22949 ) Change subject: Introduce osmo_gettid() API ...................................................................... Introduce osmo_gettid() API This API wraps conventional gettid() linux-specific API, which even in Linux itself is sometimes not properly supported/announced. This API also allows future porting to other platforms if needed, and so far falls back to getpid() if no gettid(9 can be found. Code ported from osmo-trx.git, see commit 7a07de1efd4eb7cc11c33d3ad25cb2df70aa1ef1. Related: OS#5027 Change-Id: Id7534beeb22fcd50813dab76dd68818e2ff87ec2 --- M configure.ac M include/Makefile.am A include/osmocom/core/thread.h M src/Makefile.am A src/thread.c 5 files changed, 105 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/configure.ac b/configure.ac index 2a6a180..f5af0d0 100644 --- a/configure.ac +++ b/configure.ac @@ -134,6 +134,16 @@ CHECK_TM_INCLUDES_TM_GMTOFF +# 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 + dnl Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0: ARG_ENABLE_DETECT_TLS_GCC_ARM_BUG diff --git a/include/Makefile.am b/include/Makefile.am index 8dae3d9..f0742d5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -53,6 +53,7 @@ osmocom/core/strrb.h \ osmocom/core/talloc.h \ osmocom/core/tdef.h \ + osmocom/core/thread.h \ osmocom/core/timer.h \ osmocom/core/timer_compat.h \ osmocom/core/utils.h \ diff --git a/include/osmocom/core/thread.h b/include/osmocom/core/thread.h new file mode 100644 index 0000000..40b5436 --- /dev/null +++ b/include/osmocom/core/thread.h @@ -0,0 +1,33 @@ +/*! \file thread.h + * Compatibility header with some thread related helpers + */ +/* + * (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de> + * All Rights Reserved + * Author: Pau Espin Pedrol <pespin at sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +/*! \defgroup thread Osmocom thread helpers + * @{ + * \file thread.h */ + +#pragma once + +#include <sys/types.h> + +pid_t osmo_gettid(void); diff --git a/src/Makefile.am b/src/Makefile.am index a2566a3..e56b57e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,7 @@ conv_acc.c conv_acc_generic.c sercomm.c prbs.c \ isdnhdlc.c \ tdef.c \ + thread.c \ sockaddr_str.c \ use_count.c \ exec.c \ diff --git a/src/thread.c b/src/thread.c new file mode 100644 index 0000000..956fee7 --- /dev/null +++ b/src/thread.c @@ -0,0 +1,60 @@ +/* + * (C) 2021 by sysmocom s.f.m.c. GmbH <info at sysmocom.de> + * All Rights Reserved + * + * Author: Pau Espin Pedrol <pespin at sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +/*! \addtogroup thread + * @{ + * \file thread.c + */ + +/*! \file thread.c + */ + +#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 <unistd.h> +#include <sys/types.h> + +#include <osmocom/core/thread.h> + +/*! Wrapper around Linux's gettid() to make it easily accessible on different system versions. + * If the gettid() API cannot be found, it will use the syscall directly if + * available. If no syscall is found available, then getpid() is called as + * fallback. See 'man 2 gettid' for further and details information. + * \returns This call is always successful and returns returns the thread ID of + * the calling thread (or the process ID of the current process if + * gettid() or its syscall are unavailable in the system). + */ +pid_t osmo_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 +} -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22949 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Id7534beeb22fcd50813dab76dd68818e2ff87ec2 Gerrit-Change-Number: 22949 Gerrit-PatchSet: 4 Gerrit-Owner: pespin <pespin at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210218/c5084e91/attachment.htm>