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.
This commit is contained in:
Eric Blake 2010-12-04 14:33:23 -07:00
parent 85ccf42cd0
commit e4bc372e1b
5 changed files with 27 additions and 1 deletions

View 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;
}

View File

@ -773,6 +773,7 @@ virMutexInitRecursive;
virMutexLock;
virMutexUnlock;
virThreadCreate;
virThreadID;
virThreadIsSelf;
virThreadJoin;
virThreadSelf;

View 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);

View 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)
{

View 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;