]> mj.ucw.cz Git - libucw.git/blobdiff - lib/threads.c
bgetl() should return uns instead of u32
[libucw.git] / lib / threads.c
index 0cb10d11aa7968aaecc700388b41cca39aa0fcf4..c7497f95247f5dc2d6205d1d080686d1ad02b30f 100644 (file)
 
 #include <pthread.h>
 
+#ifdef CONFIG_LINUX
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#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;
 }