X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fthreads.c;h=f5e828f313adecb9e9ef02ec368e841fcb90ac65;hb=da2f99caf76902aacb06fd389994ac79182a92da;hp=f45c8e38a95a36bf8de359e32e526748e2192283;hpb=7469a39867d251cf81e03a25922d29a49af3fee6;p=libucw.git diff --git a/lib/threads.c b/lib/threads.c index f45c8e38..f5e828f3 100644 --- a/lib/threads.c +++ b/lib/threads.c @@ -31,6 +31,17 @@ ucwlib_threads_init(void) pthread_mutex_init(&ucwlib_master_mutex, NULL); } +static int +ucwlib_tid(void) +{ + static int tid_counter; + + ucwlib_lock(); + int tid = ++tid_counter; + ucwlib_unlock(); + return tid; +} + struct ucwlib_context * ucwlib_thread_context(void) { @@ -38,6 +49,7 @@ ucwlib_thread_context(void) if (!c) { c = xmalloc_zero(sizeof(*c)); + c->thread_id = ucwlib_tid(); pthread_setspecific(ucwlib_context_key, c); } return c; @@ -58,7 +70,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; @@ -82,7 +94,7 @@ int main(void) { ucwlib_lock(); ucwlib_unlock(); - ucwlib_thread_context(); + log(L_INFO, "tid=%d", ucwlib_thread_context()->thread_id); return 0; }