tidwall / neco

Concurrency library for C (coroutines)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please support older glibc (< 2.30)

toge opened this issue · comments

commented

I met compilation error on glibc 2.23.

neco.c:(.text+0x59b7): undefined reference to `gettid'
neco.c:(.text+0x80a7): undefined reference to `gettid'
collect2: error: ld returned 1 exit status

Because gettid has been provided since glibc 2.30, there are compilation errors on glibc < 2.30.
To support older glibc, following modification seems to be required.

Original:

#elif defined(__linux__) || defined(__EMSCRIPTEN__) 
int gettid(void);
static int is_main_thread(void) {
    return getpid() == gettid();
}
#else

Try to support older glibc:

#elif defined(__EMSCRIPTEN__)
static int is_main_thread(void) {
    return getpid() == gettid();
}
#elif defined(__linux__)
  #if defined(__GLIBC__) && (__GLIBC__ >= 3 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30))
int gettid(void);
static int is_main_thread(void) {
    return getpid() == gettid();
}
  #else
#include <sys/types.h>
#include <sys/syscall.h>
static int is_main_thread(void) {
    return getpid() == (pid_t)syscall(SYS_gettid);
}
  #endif
#else

👍 updated