diff options
author | David Carlier <devnexen@gmail.com> | 2020-05-26 08:25:26 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-06-10 12:10:48 -0400 |
commit | 9548a891738424a09eae9ef6e3826ef930cdd598 (patch) | |
tree | e19b912e308f0de98c9b7cfb9ab9efe0a273bde3 | |
parent | ea39f9b643959d759b8643b4c11c4cbb3683d0ff (diff) |
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>
-rw-r--r-- | util/oslib-posix.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 062236a1ab..916f1be224 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -48,11 +48,13 @@ #ifdef __FreeBSD__ #include <sys/sysctl.h> #include <sys/user.h> +#include <sys/thr.h> #include <libutil.h> #endif #ifdef __NetBSD__ #include <sys/sysctl.h> +#include <lwp.h> #endif #include "qemu/mmap-alloc.h" @@ -84,6 +86,13 @@ int qemu_get_thread_id(void) { #if defined(__linux__) 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 return getpid(); #endif |