mirror of https://github.com/xemu-project/xemu.git
qemu-thread: add API for joinable threads
Split from Jan's original qemu-thread-posix.c patch. No semantic change, just introduce the new API that POSIX and Win32 implementations will conform to. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
d396a657ba
commit
cf21871479
6
cpus.c
6
cpus.c
|
@ -910,7 +910,8 @@ static void qemu_tcg_init_vcpu(void *_env)
|
||||||
env->halt_cond = g_malloc0(sizeof(QemuCond));
|
env->halt_cond = g_malloc0(sizeof(QemuCond));
|
||||||
qemu_cond_init(env->halt_cond);
|
qemu_cond_init(env->halt_cond);
|
||||||
tcg_halt_cond = env->halt_cond;
|
tcg_halt_cond = env->halt_cond;
|
||||||
qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env);
|
qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env,
|
||||||
|
QEMU_THREAD_DETACHED);
|
||||||
while (env->created == 0) {
|
while (env->created == 0) {
|
||||||
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
|
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
|
||||||
}
|
}
|
||||||
|
@ -926,7 +927,8 @@ static void qemu_kvm_start_vcpu(CPUState *env)
|
||||||
env->thread = g_malloc0(sizeof(QemuThread));
|
env->thread = g_malloc0(sizeof(QemuThread));
|
||||||
env->halt_cond = g_malloc0(sizeof(QemuCond));
|
env->halt_cond = g_malloc0(sizeof(QemuCond));
|
||||||
qemu_cond_init(env->halt_cond);
|
qemu_cond_init(env->halt_cond);
|
||||||
qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env);
|
qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env,
|
||||||
|
QEMU_THREAD_DETACHED);
|
||||||
while (env->created == 0) {
|
while (env->created == 0) {
|
||||||
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
|
qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,8 +541,9 @@ static int emulated_initfn(CCIDCardState *base)
|
||||||
printf("%s: failed to initialize vcard\n", EMULATED_DEV_NAME);
|
printf("%s: failed to initialize vcard\n", EMULATED_DEV_NAME);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_thread_create(&thread_id, event_thread, card);
|
qemu_thread_create(&thread_id, event_thread, card, QEMU_THREAD_DETACHED);
|
||||||
qemu_thread_create(&thread_id, handle_apdu_thread, card);
|
qemu_thread_create(&thread_id, handle_apdu_thread, card,
|
||||||
|
QEMU_THREAD_DETACHED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,13 +117,14 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex)
|
||||||
|
|
||||||
void qemu_thread_create(QemuThread *thread,
|
void qemu_thread_create(QemuThread *thread,
|
||||||
void *(*start_routine)(void*),
|
void *(*start_routine)(void*),
|
||||||
void *arg)
|
void *arg, int mode)
|
||||||
{
|
{
|
||||||
|
sigset_t set, oldset;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* Leave signal handling to the iothread. */
|
assert(mode == QEMU_THREAD_DETACHED);
|
||||||
sigset_t set, oldset;
|
|
||||||
|
|
||||||
|
/* Leave signal handling to the iothread. */
|
||||||
sigfillset(&set);
|
sigfillset(&set);
|
||||||
pthread_sigmask(SIG_SETMASK, &set, &oldset);
|
pthread_sigmask(SIG_SETMASK, &set, &oldset);
|
||||||
err = pthread_create(&thread->thread, NULL, start_routine, arg);
|
err = pthread_create(&thread->thread, NULL, start_routine, arg);
|
||||||
|
|
|
@ -243,10 +243,12 @@ static inline void qemu_thread_init(void)
|
||||||
|
|
||||||
void qemu_thread_create(QemuThread *thread,
|
void qemu_thread_create(QemuThread *thread,
|
||||||
void *(*start_routine)(void *),
|
void *(*start_routine)(void *),
|
||||||
void *arg)
|
void *arg, int mode)
|
||||||
{
|
{
|
||||||
HANDLE hThread;
|
HANDLE hThread;
|
||||||
|
|
||||||
|
assert(mode == QEMU_THREAD_DETACHED);
|
||||||
|
|
||||||
struct QemuThreadData *data;
|
struct QemuThreadData *data;
|
||||||
qemu_thread_init();
|
qemu_thread_init();
|
||||||
data = g_malloc(sizeof *data);
|
data = g_malloc(sizeof *data);
|
||||||
|
|
|
@ -13,6 +13,9 @@ typedef struct QemuThread QemuThread;
|
||||||
#include "qemu-thread-posix.h"
|
#include "qemu-thread-posix.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define QEMU_THREAD_JOINABLE 0
|
||||||
|
#define QEMU_THREAD_DETACHED 1
|
||||||
|
|
||||||
void qemu_mutex_init(QemuMutex *mutex);
|
void qemu_mutex_init(QemuMutex *mutex);
|
||||||
void qemu_mutex_destroy(QemuMutex *mutex);
|
void qemu_mutex_destroy(QemuMutex *mutex);
|
||||||
void qemu_mutex_lock(QemuMutex *mutex);
|
void qemu_mutex_lock(QemuMutex *mutex);
|
||||||
|
@ -35,8 +38,9 @@ void qemu_cond_broadcast(QemuCond *cond);
|
||||||
void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
|
void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
|
||||||
|
|
||||||
void qemu_thread_create(QemuThread *thread,
|
void qemu_thread_create(QemuThread *thread,
|
||||||
void *(*start_routine)(void*),
|
void *(*start_routine)(void *),
|
||||||
void *arg);
|
void *arg, int mode);
|
||||||
|
void *qemu_thread_join(QemuThread *thread);
|
||||||
void qemu_thread_get_self(QemuThread *thread);
|
void qemu_thread_get_self(QemuThread *thread);
|
||||||
int qemu_thread_is_self(QemuThread *thread);
|
int qemu_thread_is_self(QemuThread *thread);
|
||||||
void qemu_thread_exit(void *retval);
|
void qemu_thread_exit(void *retval);
|
||||||
|
|
|
@ -318,7 +318,7 @@ void vnc_start_worker_thread(void)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
q = vnc_queue_init();
|
q = vnc_queue_init();
|
||||||
qemu_thread_create(&q->thread, vnc_worker_thread, q);
|
qemu_thread_create(&q->thread, vnc_worker_thread, q, QEMU_THREAD_DETACHED);
|
||||||
queue = q; /* Set global queue */
|
queue = q; /* Set global queue */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue