]> mj.ucw.cz Git - libucw.git/commitdiff
Added thread_id to ucwlib_context.
authorMartin Mares <mj@ucw.cz>
Mon, 18 Dec 2006 10:59:35 +0000 (11:59 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 18 Dec 2006 10:59:35 +0000 (11:59 +0100)
lib/threads.c
lib/threads.h

index f45c8e38a95a36bf8de359e32e526748e2192283..cd1db74df31922d76777019963f9dd31cf1cc088 100644 (file)
@@ -31,6 +31,17 @@ ucwlib_threads_init(void)
   pthread_mutex_init(&ucwlib_master_mutex, NULL);
 }
 
+static int
+ucwlib_tid(void)
+{
+  static 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;
@@ -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;
 }
 
index 9e33109e72eaca794be58fd1e9e8f8ca7bfb18f2..c70354fb71dafb8ce8e6418de946dd45d8b1624d 100644 (file)
@@ -13,6 +13,7 @@
 /* This structure holds per-thread data */
 
 struct ucwlib_context {
+  int thread_id;                       // Thread ID (either kernel tid or a counter)
   int temp_counter;                    // Counter for fb-temp.c
   struct asio_queue *io_queue;         // Async I/O queue for fb-direct.c
   sh_sighandler_t *signal_handlers;    // Signal handlers for sighandler.c