]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
threads: add virThreadID for debugging use
authorEric Blake <eblake@redhat.com>
Sat, 4 Dec 2010 21:33:23 +0000 (14:33 -0700)
committerEric Blake <eblake@redhat.com>
Mon, 6 Dec 2010 16:50:20 +0000 (09:50 -0700)
* src/util/threads.h (virThreadID): New prototype.
* src/util/threads-pthread.c (virThreadID): New function.
* src/util/threads-win32.c (virThreadID): Likewise.
* src/libvirt_private.syms (threads.h): Export it.
* daemon/event.c (virEventInterruptLocked): Use it to avoid
warning on BSD systems.

daemon/event.c
src/libvirt_private.syms
src/util/threads-pthread.c
src/util/threads-win32.c
src/util/threads.h

index 0920748d19c76289772bb4f70926bca9df56ce22..01cb674459fdb842ac8805a90e7a44a9ce9cc89f 100644 (file)
@@ -653,7 +653,8 @@ static int virEventInterruptLocked(void)
 
     if (!eventLoop.running ||
         virThreadIsSelf(&eventLoop.leader)) {
-        VIR_DEBUG("Skip interrupt, %d %d", eventLoop.running, (int)eventLoop.leader.thread);
+        VIR_DEBUG("Skip interrupt, %d %d", eventLoop.running,
+                  virThreadID(&eventLoop.leader));
         return 0;
     }
 
index aaf48ab82e4bca54e3a63cad55da37dd51f95f63..e2def6c6e218a2b91f39dfe2c0d8af094c1272fb 100644 (file)
@@ -773,6 +773,7 @@ virMutexInitRecursive;
 virMutexLock;
 virMutexUnlock;
 virThreadCreate;
+virThreadID;
 virThreadIsSelf;
 virThreadJoin;
 virThreadSelf;
index bff49797bcb0fc0e8e0f595e766e3549488187db..c406f27de084f3d012c8f0047314cd0a98f5051d 100644 (file)
@@ -22,6 +22,7 @@
 #include <config.h>
 
 #include <unistd.h>
+#include <inttypes.h>
 #if HAVE_SYS_SYSCALL_H
 # include <sys/syscall.h>
 #endif
@@ -186,6 +187,8 @@ bool virThreadIsSelf(virThreadPtr thread)
     return pthread_equal(pthread_self(), thread->thread) ? true : false;
 }
 
+/* For debugging use only; this result is not guaranteed unique on BSD
+ * systems when pthread_t is a 64-bit pointer.  */
 int virThreadSelfID(void)
 {
 #if defined(HAVE_SYS_SYSCALL_H) && defined(SYS_gettid)
@@ -197,6 +200,14 @@ int virThreadSelfID(void)
 #endif
 }
 
+/* For debugging use only; this result is not guaranteed unique on BSD
+ * systems when pthread_t is a 64-bit pointer, nor does it match the
+ * thread id of virThreadSelfID on Linux.  */
+int virThreadID(virThreadPtr thread)
+{
+    return (int)(uintptr_t)thread->thread;
+}
+
 void virThreadJoin(virThreadPtr thread)
 {
     pthread_join(thread->thread, NULL);
index 436b3bd31ddc31414e186d63325b89698dc86940..ddb4737c56c981a616a0a1c9be43b28b3d231b76 100644 (file)
@@ -299,11 +299,18 @@ bool virThreadIsSelf(virThreadPtr thread)
     return self.thread == thread->thread ? true : false;
 }
 
+/* For debugging use only; see comments in threads-pthread.c.  */
 int virThreadSelfID(void)
 {
     return (int)GetCurrentThreadId();
 }
 
+/* For debugging use only; see comments in threads-pthread.c.  */
+int virThreadID(virThreadPtr thread)
+{
+    return (int)thread->thread;
+}
+
 
 void virThreadJoin(virThreadPtr thread)
 {
index fa00a91014d543fabe306ab20949a065346fd986..35e319e6d551392cb678dae2a8bd70c8553c3eba 100644 (file)
@@ -51,7 +51,13 @@ int virThreadCreate(virThreadPtr thread,
 void virThreadSelf(virThreadPtr thread);
 bool virThreadIsSelf(virThreadPtr thread);
 void virThreadJoin(virThreadPtr thread);
+
+/* These next two functions are for debugging only, since they are not
+ * guaranteed to give unique values for distinct threads on all
+ * architectures, nor are the two functions guaranteed to give the same
+ * value for the same thread. */
 int virThreadSelfID(void);
+int virThreadID(virThreadPtr thread);
 
 int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
 int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;