mirror of https://github.com/xemu-project/xemu.git
util/oslib: Returns the real thread identifier on FreeBSD and NetBSD
getpid is good enough in a mono thread context, however thr_self/_lwp_self reflects the real current thread identifier from a given process. Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: David Carlier <devnexen@gmail.com>
This commit is contained in:
parent
ea39f9b643
commit
9548a89173
|
@ -48,11 +48,13 @@
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/user.h>
|
#include <sys/user.h>
|
||||||
|
#include <sys/thr.h>
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __NetBSD__
|
#ifdef __NetBSD__
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <lwp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "qemu/mmap-alloc.h"
|
#include "qemu/mmap-alloc.h"
|
||||||
|
@ -84,6 +86,13 @@ int qemu_get_thread_id(void)
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
return syscall(SYS_gettid);
|
return syscall(SYS_gettid);
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
/* thread id is up to INT_MAX */
|
||||||
|
long tid;
|
||||||
|
thr_self(&tid);
|
||||||
|
return (int)tid;
|
||||||
|
#elif defined(__NetBSD__)
|
||||||
|
return _lwp_self();
|
||||||
#else
|
#else
|
||||||
return getpid();
|
return getpid();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue