From patchwork Tue Dec 6 17:05:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 129747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 910A61007D6 for ; Wed, 7 Dec 2011 04:06:40 +1100 (EST) Received: from localhost ([::1]:41642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXyTU-00082J-Ud for incoming@patchwork.ozlabs.org; Tue, 06 Dec 2011 12:06:36 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXyT9-0007XY-C4 for qemu-devel@nongnu.org; Tue, 06 Dec 2011 12:06:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXyT3-00068m-AP for qemu-devel@nongnu.org; Tue, 06 Dec 2011 12:06:15 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:42926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXyT3-00068U-4S for qemu-devel@nongnu.org; Tue, 06 Dec 2011 12:06:09 -0500 Received: by iafj26 with SMTP id j26so323826iaf.4 for ; Tue, 06 Dec 2011 09:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=JYJBQ/IsNhyGZi/AYPTF6pOFdTjZkyQWvNDy80CizHM=; b=SNQPel3VN9Omf3ERCnPAIvz5iUE5PB1ziDwYyraQUFWPTsj1vgJC5/4CQe/6sdOgK1 X/ZJxcDiViGmV9Y38wHxN9VLqimPTlTmybnU6Dlc10ZZt53DOO7dLcg0YJHUyH+Vbo6E YZD8PHYKAXcdNBDl7RvO8aydFGWS6m9qu8tvo= Received: by 10.42.154.69 with SMTP id p5mr15102108icw.11.1323191168405; Tue, 06 Dec 2011 09:06:08 -0800 (PST) Received: from localhost.localdomain (93-34-178-147.ip50.fastwebnet.it. [93.34.178.147]) by mx.google.com with ESMTPS id ew6sm50623315igc.4.2011.12.06.09.06.06 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Dec 2011 09:06:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 6 Dec 2011 18:05:52 +0100 Message-Id: <1323191155-22549-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1323191155-22549-1-git-send-email-pbonzini@redhat.com> References: <1323191155-22549-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Cc: jan.kiszka@siemens.com, alevy@redhat.com Subject: [Qemu-devel] [PATCH 1/4] qemu-thread: add API for joinable threads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka 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 Signed-off-by: Paolo Bonzini --- cpus.c | 6 ++++-- hw/ccid-card-emulated.c | 5 +++-- qemu-thread-posix.c | 7 ++++--- qemu-thread-win32.c | 4 +++- qemu-thread.h | 8 ++++++-- ui/vnc-jobs-async.c | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cpus.c b/cpus.c index ca46ec6..cbb4617 100644 --- a/cpus.c +++ b/cpus.c @@ -910,7 +910,8 @@ static void qemu_tcg_init_vcpu(void *_env) env->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(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) { 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->halt_cond = g_malloc0(sizeof(QemuCond)); 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) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c index 092301b..9fe9db5 100644 --- a/hw/ccid-card-emulated.c +++ b/hw/ccid-card-emulated.c @@ -541,8 +541,9 @@ static int emulated_initfn(CCIDCardState *base) printf("%s: failed to initialize vcard\n", EMULATED_DEV_NAME); return -1; } - qemu_thread_create(&thread_id, event_thread, card); - qemu_thread_create(&thread_id, handle_apdu_thread, card); + qemu_thread_create(&thread_id, event_thread, card, QEMU_THREAD_DETACHED); + qemu_thread_create(&thread_id, handle_apdu_thread, card, + QEMU_THREAD_DETACHED); return 0; } diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c index ac3c0c9..49d3388 100644 --- a/qemu-thread-posix.c +++ b/qemu-thread-posix.c @@ -117,13 +117,14 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) void qemu_thread_create(QemuThread *thread, void *(*start_routine)(void*), - void *arg) + void *arg, int mode) { + sigset_t set, oldset; int err; - /* Leave signal handling to the iothread. */ - sigset_t set, oldset; + assert(mode == QEMU_THREAD_DETACHED); + /* Leave signal handling to the iothread. */ sigfillset(&set); pthread_sigmask(SIG_SETMASK, &set, &oldset); err = pthread_create(&thread->thread, NULL, start_routine, arg); diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c index db8e744..ff80e84 100644 --- a/qemu-thread-win32.c +++ b/qemu-thread-win32.c @@ -243,10 +243,12 @@ static inline void qemu_thread_init(void) void qemu_thread_create(QemuThread *thread, void *(*start_routine)(void *), - void *arg) + void *arg, int mode) { HANDLE hThread; + assert(mode == QEMU_THREAD_DETACHED); + struct QemuThreadData *data; qemu_thread_init(); data = g_malloc(sizeof *data); diff --git a/qemu-thread.h b/qemu-thread.h index e008b60..a78a8f2 100644 --- a/qemu-thread.h +++ b/qemu-thread.h @@ -13,6 +13,9 @@ typedef struct QemuThread QemuThread; #include "qemu-thread-posix.h" #endif +#define QEMU_THREAD_JOINABLE 0 +#define QEMU_THREAD_DETACHED 1 + void qemu_mutex_init(QemuMutex *mutex); void qemu_mutex_destroy(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_thread_create(QemuThread *thread, - void *(*start_routine)(void*), - void *arg); + void *(*start_routine)(void *), + void *arg, int mode); +void *qemu_thread_join(QemuThread *thread); void qemu_thread_get_self(QemuThread *thread); int qemu_thread_is_self(QemuThread *thread); void qemu_thread_exit(void *retval); diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c index de5ea6b..9b3016c 100644 --- a/ui/vnc-jobs-async.c +++ b/ui/vnc-jobs-async.c @@ -318,7 +318,7 @@ void vnc_start_worker_thread(void) return ; 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 */ }