[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] threads: add virThreadID for debugging use



* 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             |    3 ++-
 src/libvirt_private.syms   |    1 +
 src/util/threads-pthread.c |    6 ++++++
 src/util/threads-win32.c   |    5 +++++
 src/util/threads.h         |    5 +++++
 5 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/daemon/event.c b/daemon/event.c
index 0920748..01cb674 100644
--- a/daemon/event.c
+++ b/daemon/event.c
@@ -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;
     }

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index aaf48ab..e2def6c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -773,6 +773,7 @@ virMutexInitRecursive;
 virMutexLock;
 virMutexUnlock;
 virThreadCreate;
+virThreadID;
 virThreadIsSelf;
 virThreadJoin;
 virThreadSelf;
diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c
index bff4979..826b9d1 100644
--- a/src/util/threads-pthread.c
+++ b/src/util/threads-pthread.c
@@ -22,6 +22,7 @@
 #include <config.h>

 #include <unistd.h>
+#include <inttypes.h>
 #if HAVE_SYS_SYSCALL_H
 # include <sys/syscall.h>
 #endif
@@ -197,6 +198,11 @@ int virThreadSelfID(void)
 #endif
 }

+int virThreadID(virThreadPtr thread)
+{
+    return (int)(uintptr_t)thread->thread;
+}
+
 void virThreadJoin(virThreadPtr thread)
 {
     pthread_join(thread->thread, NULL);
diff --git a/src/util/threads-win32.c b/src/util/threads-win32.c
index 436b3bd..2f4bcfc 100644
--- a/src/util/threads-win32.c
+++ b/src/util/threads-win32.c
@@ -304,6 +304,11 @@ int virThreadSelfID(void)
     return (int)GetCurrentThreadId();
 }

+int virThreadID(virThreadPtr thread)
+{
+    return (int)thread->thread;
+}
+

 void virThreadJoin(virThreadPtr thread)
 {
diff --git a/src/util/threads.h b/src/util/threads.h
index fa00a91..de28db6 100644
--- a/src/util/threads.h
+++ b/src/util/threads.h
@@ -51,7 +51,12 @@ 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. */
 int virThreadSelfID(void);
+int virThreadID(virThreadPtr thread);

 int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
 int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK;
-- 
1.7.3.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]