Comments
Patch
@@ -735,6 +735,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
CPUState *cpu = ENV_GET_CPU(env);
int r;
+ pthread_setspecific(qemu_thread_key, cpu->thread);
qemu_mutex_lock(&qemu_global_mutex);
qemu_thread_get_self(cpu->thread);
env->thread_id = qemu_get_thread_id();
@@ -19,6 +19,8 @@
#include <string.h>
#include "qemu-thread.h"
+pthread_key_t qemu_thread_key;
+
static void error_exit(int err, const char *msg)
{
fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
@@ -151,6 +153,11 @@ void qemu_thread_get_self(QemuThread *thread)
thread->thread = pthread_self();
}
+void qemu_thread_key_create(void)
+{
+ pthread_key_create(&qemu_thread_key, NULL);
+}
+
bool qemu_thread_is_self(QemuThread *thread)
{
return pthread_equal(pthread_self(), thread->thread);
@@ -14,4 +14,6 @@ struct QemuThread {
pthread_t thread;
};
+extern pthread_key_t qemu_thread_key;
+
#endif
@@ -46,4 +46,5 @@ void qemu_thread_get_self(QemuThread *thread);
bool qemu_thread_is_self(QemuThread *thread);
void qemu_thread_exit(void *retval);
+void qemu_thread_key_create(void);
#endif
@@ -149,6 +149,7 @@ int main(int argc, char **argv)
#include "qemu-options.h"
#include "qmp-commands.h"
#include "main-loop.h"
+#include "qemu-thread.h"
#ifdef CONFIG_VIRTFS
#include "fsdev/qemu-fsdev.h"
#endif
@@ -2342,6 +2343,7 @@ int qemu_init_main_loop(void)
return main_loop_init();
}
+
int main(int argc, char **argv, char **envp)
{
int i;
@@ -3483,6 +3485,8 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
+ qemu_thread_key_create();
+
os_set_line_buffering();
if (init_timer_alarm() < 0) {