X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fthreads.c;h=c7497f95247f5dc2d6205d1d080686d1ad02b30f;hb=7119957a2df57af617f432dd429e1d6ae5cbe0fd;hp=f5e828f313adecb9e9ef02ec368e841fcb90ac65;hpb=314027856c1d6ccb92bc625f4284cd36655fb154;p=libucw.git diff --git a/lib/threads.c b/lib/threads.c index f5e828f3..c7497f95 100644 --- a/lib/threads.c +++ b/lib/threads.c @@ -14,6 +14,20 @@ #include +#ifdef CONFIG_LINUX +#include +#include +#include +#ifdef __NR_gettid +static pid_t +gettid(void) +{ + return syscall(__NR_gettid); +} +#define CONFIG_USE_GETTID +#endif +#endif + static pthread_key_t ucwlib_context_key; static pthread_mutex_t ucwlib_master_mutex; @@ -35,9 +49,17 @@ static int ucwlib_tid(void) { static int tid_counter; + int tid; + +#ifdef CONFIG_USE_GETTID + tid = gettid(); + if (tid > 0) + return tid; + /* The syscall might be unimplemented */ +#endif ucwlib_lock(); - int tid = ++tid_counter; + tid = ++tid_counter; ucwlib_unlock(); return tid; }