mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
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:
parent
85ccf42cd0
commit
e4bc372e1b
@ -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;
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,7 @@ virMutexInitRecursive;
|
||||
virMutexLock;
|
||||
virMutexUnlock;
|
||||
virThreadCreate;
|
||||
virThreadID;
|
||||
virThreadIsSelf;
|
||||
virThreadJoin;
|
||||
virThreadSelf;
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user