initial support to remove a static variable in qemu-thread-win32.c

This commit is contained in:
Nguyen Anh Quynh 2015-09-02 16:13:12 +08:00
parent a94e31165d
commit 8b39ec5b0c
6 changed files with 18 additions and 17 deletions

View File

@ -172,6 +172,8 @@ struct uc_struct {
bool block_full;
MemoryRegion **mapped_blocks;
uint32_t mapped_block_count;
void *qemu_thread_data; // to support cross compile to Windows (qemu-thread-win32.c)
};
#include "qemu_macro.h"

View File

@ -124,7 +124,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
struct uc_struct *uc = cpu->uc;
//qemu_tcg_init_cpu_signals();
qemu_thread_get_self(cpu->thread);
qemu_thread_get_self(uc, cpu->thread);
qemu_mutex_lock(&uc->qemu_global_mutex);
CPU_FOREACH(cpu) {
@ -185,7 +185,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu)
uc->tcg_halt_cond = cpu->halt_cond;
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
cpu->cpu_index);
qemu_thread_create(cpu->thread, thread_name, qemu_tcg_cpu_thread_fn,
qemu_thread_create(uc, cpu->thread, thread_name, qemu_tcg_cpu_thread_fn,
cpu, QEMU_THREAD_JOINABLE);
#ifdef _WIN32
cpu->hThread = qemu_thread_get_handle(cpu->thread);

View File

@ -52,12 +52,13 @@ void qemu_event_reset(QemuEvent *ev);
void qemu_event_wait(QemuEvent *ev);
void qemu_event_destroy(QemuEvent *ev);
void qemu_thread_create(QemuThread *thread, const char *name,
struct uc_struct;
void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
void *(*start_routine)(void *),
void *arg, int mode);
void *qemu_thread_join(QemuThread *thread);
void qemu_thread_get_self(QemuThread *thread);
void qemu_thread_get_self(struct uc_struct *uc, QemuThread *thread);
bool qemu_thread_is_self(QemuThread *thread);
void qemu_thread_exit(void *retval);
void qemu_thread_exit(struct uc_struct *uc, void *retval);
#endif

View File

@ -389,7 +389,7 @@ void qemu_event_wait(QemuEvent *ev)
}
}
void qemu_thread_create(QemuThread *thread, const char *name,
void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
void *(*start_routine)(void*),
void *arg, int mode)
{
@ -426,7 +426,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,
pthread_attr_destroy(&attr);
}
void qemu_thread_get_self(QemuThread *thread)
void qemu_thread_get_self(struct uc_struct *uc, QemuThread *thread)
{
thread->thread = pthread_self();
}
@ -436,7 +436,7 @@ bool qemu_thread_is_self(QemuThread *thread)
return pthread_equal(pthread_self(), thread->thread);
}
void qemu_thread_exit(void *retval)
void qemu_thread_exit(struct uc_struct *uc, void *retval)
{
pthread_exit(retval);
}

View File

@ -266,8 +266,6 @@ struct QemuThreadData {
CRITICAL_SECTION cs;
};
static __thread QemuThreadData *qemu_thread_data;
static unsigned __stdcall win32_start_routine(void *arg)
{
QemuThreadData *data = (QemuThreadData *) arg;
@ -278,14 +276,13 @@ static unsigned __stdcall win32_start_routine(void *arg)
g_free(data);
data = NULL;
}
qemu_thread_data = data;
qemu_thread_exit(start_routine(thread_arg));
abort();
}
void qemu_thread_exit(void *arg)
void qemu_thread_exit(struct uc_struct *uc, void *arg)
{
QemuThreadData *data = qemu_thread_data;
QemuThreadData *data = uc->qemu_thread_data;
if (data) {
assert(data->mode != QEMU_THREAD_DETACHED);
@ -326,7 +323,7 @@ void *qemu_thread_join(QemuThread *thread)
return ret;
}
void qemu_thread_create(QemuThread *thread, const char *name,
void qemu_thread_create(struct uc_struct *uc, QemuThread *thread, const char *name,
void *(*start_routine)(void *),
void *arg, int mode)
{
@ -338,6 +335,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,
data->arg = arg;
data->mode = mode;
data->exited = false;
uc->qemu_thread_data = data;
if (data->mode != QEMU_THREAD_DETACHED) {
InitializeCriticalSection(&data->cs);
@ -352,9 +350,9 @@ void qemu_thread_create(QemuThread *thread, const char *name,
thread->data = (mode == QEMU_THREAD_DETACHED) ? NULL : data;
}
void qemu_thread_get_self(QemuThread *thread)
void qemu_thread_get_self(struct uc_struct *uc, QemuThread *thread)
{
thread->data = qemu_thread_data;
thread->data = uc->qemu_thread_data;
thread->tid = GetCurrentThreadId();
}

2
uc.c
View File

@ -465,7 +465,7 @@ static void enable_emu_timer(uch handle, uint64_t timeout)
struct uc_struct *uc = (struct uc_struct *)handle;
uc->timeout = timeout;
qemu_thread_create(&uc->timer, "timeout", _timeout_fn,
qemu_thread_create(uc, &uc->timer, "timeout", _timeout_fn,
uc, QEMU_THREAD_JOINABLE);
}