X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fthreads.c;h=d2e0f220d769bce15c34935cb12ca259e8413cfe;hb=8f5b597a0c9187c0d7bc7785be0886023203dbfd;hp=cd1db74df31922d76777019963f9dd31cf1cc088;hpb=7b260d8cd4ee39a6ca9154b4324dc052c86fce4b;p=libucw.git diff --git a/lib/threads.c b/lib/threads.c index cd1db74d..d2e0f220 100644 --- a/lib/threads.c +++ b/lib/threads.c @@ -14,6 +14,15 @@ #include +#ifdef CONFIG_LINUX +#include +#include +#ifdef __NR_gettid +static _syscall0(pid_t, gettid) +#define CONFIG_USE_GETTID +#endif +#endif + static pthread_key_t ucwlib_context_key; static pthread_mutex_t ucwlib_master_mutex; @@ -34,10 +43,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 +87,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;