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
add_subdirectory(include)
@ -7,14 +7,14 @@ add_library(parson STATIC parson.c)
target_include_directories(parson PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
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}")
set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON)
add_library(parson-static STATIC parson.c)
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}")
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)
* SPDX-License-Identifier: MIT */
#ifndef COMPAT_H
#define COMPAT_H
#define _GNU_SOURCE /* Only here */
#include <sys/types.h>
pid_t gettid(void);
#include "compat.h"
#include <unistd.h>
#include <errno.h>
/* Define gettid for older glibc versions (below 2.30) */
#if defined(__GLIBC__)
#if !__GLIBC_PREREQ(2, 30)
#include <sys/syscall.h>
#include <unistd.h>
static inline pid_t
static pid_t
gettid(void)
{
return (pid_t) syscall(SYS_gettid);
@ -23,12 +22,13 @@ gettid(void)
#endif /* !__GLIBC_PREREQ(2, 30) */
#endif /* defined(__GLIBC__) */
/* usleep is deprecated */
pid_t
get_tid(void)
{
return gettid();
}
#include <time.h>
#include <errno.h>
static inline int
int
sleep_us(long usec)
{
struct timespec ts;
@ -48,5 +48,3 @@ sleep_us(long usec)
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_proc_init(1, rankname, getpid());
ovni_proc_set_rank(rank, nranks);
ovni_thread_init(gettid());
ovni_thread_init(get_tid());
/* All ranks inform CPUs */
for (int i = 0; i < nranks; i++)
@ -98,7 +98,7 @@ instr_start(int rank, int nranks)
int curcpu = rank;
dbg("thread %d has cpu %d (ncpus=%d)",
gettid(), curcpu, nranks);
get_tid(), curcpu, nranks);
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_thread_init(gettid());
ovni_thread_init(get_tid());
/* Only the rank 0 inform about all CPUs */
if (rank == 0) {
@ -67,7 +67,7 @@ instr_start(int rank, int nranks)
int curcpu = rank;
fprintf(stderr, "thread %d has cpu %d (ncpus=%d)\n",
gettid(), curcpu, nranks);
get_tid(), curcpu, nranks);
instr_thread_execute(curcpu, -1, 0);
}

View File

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

View File

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

View File

@ -46,7 +46,7 @@ polling_func(void *arg)
static inline void
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};