tidwall / neco

Concurrency library for C (coroutines)
MIT License
1.1k stars 79 forks source link

Please support older glibc (< 2.30) #6

Open toge opened 4 months ago

toge commented 4 months ago

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
tidwall commented 4 months ago

👍 updated