X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fthreads.c;h=c7497f95247f5dc2d6205d1d080686d1ad02b30f;hb=90afcc18dbf7cb6c682e1efb994007f03e304422;hp=cd1db74df31922d76777019963f9dd31cf1cc088;hpb=63b7d5c6c89182792601e29326131e6b12321df9;p=libucw.git diff --git a/lib/threads.c b/lib/threads.c index cd1db74d..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; @@ -34,10 +48,18 @@ ucwlib_threads_init(void) static int ucwlib_tid(void) { - static tid_counter; + 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; } @@ -70,7 +92,7 @@ ucwlib_unlock(void) #else struct ucwlib_context * -ucw_thread_context(void) +ucwlib_thread_context(void) { static struct ucwlib_context ucwlib_context; return &ucwlib_context;