From 39b65b1e67676b35add5faed19a56077fb6c35ec Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 11 Jan 2022 15:47:17 +0100 Subject: [PATCH] Define gettid for old glibc versions --- compat.h | 40 ++++++++++++++++++++++++++++++++++++++++ ovni.c | 6 +----- test/flush.c | 9 +-------- test/mp-rank.c | 1 + test/mp-simple.c | 1 + test_speed.c | 6 +----- 6 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 compat.h diff --git a/compat.h b/compat.h new file mode 100644 index 0000000..1da332e --- /dev/null +++ b/compat.h @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2022 Barcelona Supercomputing Center (BSC) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef COMPAT_H +#define COMPAT_H + +#define _GNU_SOURCE +#include +#include + +/* Define gettid for older glibc versions (below 2.30) */ +#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 30) +static inline pid_t gettid(void) +{ + return (pid_t)syscall(SYS_gettid); +} +#endif + +#endif // COMPAT_H diff --git a/ovni.c b/ovni.c index c675cec..170a83f 100644 --- a/ovni.c +++ b/ovni.c @@ -37,11 +37,7 @@ #include "ovni.h" #include "common.h" #include "parson.h" - -#ifndef gettid -# include -# define gettid() ((pid_t)syscall(SYS_gettid)) -#endif +#include "compat.h" /* Data per process */ struct ovni_rproc rproc = {0}; diff --git a/test/flush.c b/test/flush.c index 33b5a67..2b061e0 100644 --- a/test/flush.c +++ b/test/flush.c @@ -28,14 +28,7 @@ #include #include "ovni.h" - -// Define gettid for older glibc versions (below 2.30) -#if !__GLIBC_PREREQ(2, 30) -static inline pid_t gettid(void) -{ - return (pid_t)syscall(SYS_gettid); -} -#endif +#include "compat.h" static inline void init(void) diff --git a/test/mp-rank.c b/test/mp-rank.c index 9a3419b..569adc6 100644 --- a/test/mp-rank.c +++ b/test/mp-rank.c @@ -18,6 +18,7 @@ #define _GNU_SOURCE #include "ovni.h" +#include "compat.h" #include #include diff --git a/test/mp-simple.c b/test/mp-simple.c index 3d8a389..5c8dfe4 100644 --- a/test/mp-simple.c +++ b/test/mp-simple.c @@ -18,6 +18,7 @@ #define _GNU_SOURCE #include "ovni.h" +#include "compat.h" #include #include diff --git a/test_speed.c b/test_speed.c index b1280c5..3e42567 100644 --- a/test_speed.c +++ b/test_speed.c @@ -27,11 +27,7 @@ #include #include "ovni.h" - -#ifndef gettid -# include -# define gettid() ((pid_t)syscall(SYS_gettid)) -#endif +#include "compat.h" static inline void init(void)