1 #define _GNU_SOURCE 2 #include <unistd.h> 3 #include "syscall.h" 4 #include "pthread_impl.h" 5 6 #define ZERO (0) 7 #define NEGATIVE_ONE (-1) 8 gettid(void)9pid_t gettid(void) 10 { 11 pid_t tid = __pthread_self()->tid; 12 if (tid == ZERO || tid == NEGATIVE_ONE) { 13 return __syscall(SYS_gettid); 14 } 15 return tid; 16 } 17