Skip to content

Commit

Permalink
Merge pull request #286 from nerijus/master
Browse files Browse the repository at this point in the history
Fix undefined reference to 'gettid' on CentOS 8
  • Loading branch information
elFarto authored May 6, 2024
2 parents 746d551 + 66d1693 commit fc5ce86
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/vabackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,33 @@
#if __has_include(<pthread_np.h>)
#include <pthread_np.h>
#define gettid pthread_getthreadid_np
#define HAVE_GETTID 1
#endif

#ifndef HAVE_GETTID
#include <sys/syscall.h>
/* Bionic and glibc >= 2.30 declare gettid() system call wrapper in unistd.h and
* has a definition for it */
#ifdef __BIONIC__
#define HAVE_GETTID 1
#elif !defined(__GLIBC_PREREQ)
#define HAVE_GETTID 0
#elif !__GLIBC_PREREQ(2,30)
#define HAVE_GETTID 0
#else
#define HAVE_GETTID 1
#endif
#endif

static pid_t nv_gettid(void)
{
#if HAVE_GETTID
return gettid();
#else
return syscall(__NR_gettid);
#endif
}

static pthread_mutex_t concurrency_mutex = PTHREAD_MUTEX_INITIALIZER;
static uint32_t instances;
static uint32_t max_instances;
Expand Down Expand Up @@ -176,7 +201,7 @@ void logger(const char *filename, const char *function, int line, const char *ms
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);

fprintf(LOG_OUTPUT, "%10ld.%09ld [%d-%d] %s:%4d %24s %s\n", (long)tp.tv_sec, tp.tv_nsec, getpid(), gettid(), filename, line, function, formattedMessage);
fprintf(LOG_OUTPUT, "%10ld.%09ld [%d-%d] %s:%4d %24s %s\n", (long)tp.tv_sec, tp.tv_nsec, getpid(), nv_gettid(), filename, line, function, formattedMessage);
fflush(LOG_OUTPUT);
}

Expand Down

0 comments on commit fc5ce86

Please sign in to comment.