Constraint _GNU_SOURCE in compat.c only

This commit is contained in:
Rodrigo Arias 2023-03-22 17:06:52 +01:00 committed by Rodrigo Arias Mallo
parent 1e822c248e
commit 848a1de963
8 changed files with 34 additions and 24 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) # Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
add_subdirectory(include) add_subdirectory(include)
@ -7,14 +7,14 @@ add_library(parson STATIC parson.c)
target_include_directories(parson PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(parson PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
set_property(TARGET parson PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET parson PROPERTY POSITION_INDEPENDENT_CODE ON)
add_library(common STATIC common.c) add_library(common STATIC common.c compat.c)
target_include_directories(common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON)
add_library(parson-static STATIC parson.c) add_library(parson-static STATIC parson.c)
target_include_directories(parson-static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(parson-static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
add_library(common-static STATIC common.c) add_library(common-static STATIC common.c compat.c)
target_include_directories(common-static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(common-static PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" ) configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" )

View File

@ -1,20 +1,19 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) /* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: MIT */ * SPDX-License-Identifier: MIT */
#ifndef COMPAT_H #define _GNU_SOURCE /* Only here */
#define COMPAT_H
#include <sys/types.h> #include "compat.h"
pid_t gettid(void); #include <unistd.h>
#include <errno.h>
/* Define gettid for older glibc versions (below 2.30) */ /* Define gettid for older glibc versions (below 2.30) */
#if defined(__GLIBC__) #if defined(__GLIBC__)
#if !__GLIBC_PREREQ(2, 30) #if !__GLIBC_PREREQ(2, 30)
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h>
static inline pid_t static pid_t
gettid(void) gettid(void)
{ {
return (pid_t) syscall(SYS_gettid); return (pid_t) syscall(SYS_gettid);
@ -23,12 +22,13 @@ gettid(void)
#endif /* !__GLIBC_PREREQ(2, 30) */ #endif /* !__GLIBC_PREREQ(2, 30) */
#endif /* defined(__GLIBC__) */ #endif /* defined(__GLIBC__) */
/* usleep is deprecated */ pid_t
get_tid(void)
{
return gettid();
}
#include <time.h> int
#include <errno.h>
static inline int
sleep_us(long usec) sleep_us(long usec)
{ {
struct timespec ts; struct timespec ts;
@ -48,5 +48,3 @@ sleep_us(long usec)
return res; return res;
} }
#endif /* COMPAT_H */

12
src/compat.h Normal file
View File

@ -0,0 +1,12 @@
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: MIT */
#ifndef COMPAT_H
#define COMPAT_H
#include <time.h>
pid_t get_tid(void);
int sleep_us(long usec);
#endif /* COMPAT_H */

View File

@ -89,7 +89,7 @@ instr_start(int rank, int nranks)
ovni_version_check(); ovni_version_check();
ovni_proc_init(1, rankname, getpid()); ovni_proc_init(1, rankname, getpid());
ovni_proc_set_rank(rank, nranks); ovni_proc_set_rank(rank, nranks);
ovni_thread_init(gettid()); ovni_thread_init(get_tid());
/* All ranks inform CPUs */ /* All ranks inform CPUs */
for (int i = 0; i < nranks; i++) for (int i = 0; i < nranks; i++)
@ -98,7 +98,7 @@ instr_start(int rank, int nranks)
int curcpu = rank; int curcpu = rank;
dbg("thread %d has cpu %d (ncpus=%d)", dbg("thread %d has cpu %d (ncpus=%d)",
gettid(), curcpu, nranks); get_tid(), curcpu, nranks);
instr_thread_execute(curcpu, -1, 0); instr_thread_execute(curcpu, -1, 0);
} }

View File

@ -55,7 +55,7 @@ instr_start(int rank, int nranks)
ovni_proc_set_rank(rank, nranks); ovni_proc_set_rank(rank, nranks);
ovni_thread_init(gettid()); ovni_thread_init(get_tid());
/* Only the rank 0 inform about all CPUs */ /* Only the rank 0 inform about all CPUs */
if (rank == 0) { if (rank == 0) {
@ -67,7 +67,7 @@ instr_start(int rank, int nranks)
int curcpu = rank; int curcpu = rank;
fprintf(stderr, "thread %d has cpu %d (ncpus=%d)\n", fprintf(stderr, "thread %d has cpu %d (ncpus=%d)\n",
gettid(), curcpu, nranks); get_tid(), curcpu, nranks);
instr_thread_execute(curcpu, -1, 0); instr_thread_execute(curcpu, -1, 0);
} }

View File

@ -37,7 +37,7 @@ start_delayed(int rank, int nranks)
ovni_version_check(); ovni_version_check();
ovni_proc_init(1, rankname, getpid()); ovni_proc_init(1, rankname, getpid());
ovni_proc_set_rank(rank, nranks); ovni_proc_set_rank(rank, nranks);
ovni_thread_init(gettid()); ovni_thread_init(get_tid());
/* All ranks inform CPUs */ /* All ranks inform CPUs */
for (int i = 0; i < nranks; i++) for (int i = 0; i < nranks; i++)
@ -46,7 +46,7 @@ start_delayed(int rank, int nranks)
int curcpu = rank; int curcpu = rank;
dbg("thread %d has cpu %d (ncpus=%d)", dbg("thread %d has cpu %d (ncpus=%d)",
gettid(), curcpu, nranks); get_tid(), curcpu, nranks);
delta = ((int64_t) rank) * 2LL * 3600LL * 1000LL * 1000LL * 1000LL; delta = ((int64_t) rank) * 2LL * 3600LL * 1000LL * 1000LL * 1000LL;
thread_execute_delayed(curcpu, -1, 0); thread_execute_delayed(curcpu, -1, 0);

View File

@ -20,7 +20,7 @@ init(void)
} }
ovni_proc_init(0, hostname, getpid()); ovni_proc_init(0, hostname, getpid());
ovni_thread_init(gettid()); ovni_thread_init(get_tid());
ovni_add_cpu(0, 0); ovni_add_cpu(0, 0);
} }

View File

@ -46,7 +46,7 @@ polling_func(void *arg)
static inline void static inline void
instr_thread_start(int32_t cpu, int32_t creator_tid, uint64_t tag) instr_thread_start(int32_t cpu, int32_t creator_tid, uint64_t tag)
{ {
ovni_thread_init(gettid()); ovni_thread_init(get_tid());
struct ovni_ev ev = {0}; struct ovni_ev ev = {0};