From patchwork Sat Feb 26 15:40:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 84650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 075B8B70D2 for ; Sun, 27 Feb 2011 02:48:42 +1100 (EST) Received: from localhost ([127.0.0.1]:36314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PtMNf-0005Yr-I5 for incoming@patchwork.ozlabs.org; Sat, 26 Feb 2011 10:48:27 -0500 Received: from [140.186.70.92] (port=40482 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PtMG3-0002Fc-Qc for qemu-devel@nongnu.org; Sat, 26 Feb 2011 10:40:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PtMG1-0007T9-Pl for qemu-devel@nongnu.org; Sat, 26 Feb 2011 10:40:35 -0500 Received: from mail-wy0-f173.google.com ([74.125.82.173]:42749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PtMG1-0007Qr-Jq for qemu-devel@nongnu.org; Sat, 26 Feb 2011 10:40:33 -0500 Received: by mail-wy0-f173.google.com with SMTP id 29so2615616wyb.4 for ; Sat, 26 Feb 2011 07:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=ExauzCAsr4L1BdjykkhaDaxzKiHP3pQYD5bLOWHUWks=; b=jCa1vLkLSNUW6VLvuoJCZCT/7RHQB3kI6iJEvIV1WlGgxpE5h1MZir3yRkXNbIf9qj OgV/nBDk54gMbfOx42OOeDtiOuPhNiOGgbLCaGhHvlFchoZynXI40BnQw+aGHnnYJ6XC a2mGOHGKpsZeOHgb0EMs7bgyGV4ETz0/DNEto= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=wyImcqNQN2l7nPMq4C4vz1ild8EP0kmcyOyHl2MrS+1n4cLSBHeMwNhzltQibSC0I7 qeAbSYXTKNCUjX0iUDWrEo3HdGabwfQU8I4q/N26gJGFri0ErzM28XakjIvGcbs2iw2F rF6fGU9TaxbdX9HEnOcNcNv/I9CdKlZG3I8IE= Received: by 10.227.128.75 with SMTP id j11mr1326880wbs.60.1298734833166; Sat, 26 Feb 2011 07:40:33 -0800 (PST) Received: from localhost.localdomain (93-34-149-100.ip50.fastwebnet.it [93.34.149.100]) by mx.google.com with ESMTPS id f27sm1592788wbf.1.2011.02.26.07.40.31 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 Feb 2011 07:40:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 26 Feb 2011 16:40:01 +0100 Message-Id: <1298734819-1960-5-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.4 In-Reply-To: <1298734819-1960-1-git-send-email-pbonzini@redhat.com> References: <1298734819-1960-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Cc: jan.kiszka@siemens.com, aurelien@aurel32.net Subject: [Qemu-devel] [PATCH v2 upstream 04/22] Refactor thread retrieval and check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka We have qemu_cpu_self and qemu_thread_self. The latter is retrieving the current thread, the former is checking for equality (using CPUState). We also have qemu_thread_equal which is only used like qemu_cpu_self. This refactors the interfaces, creating qemu_cpu_is_self and qemu_thread_is_self as well ass qemu_thread_get_self. Signed-off-by: Jan Kiszka Signed-off-by: Paolo Bonzini --- cpus.c | 22 ++++++++-------------- exec.c | 2 +- qemu-common.h | 2 +- qemu-thread.c | 6 +++--- qemu-thread.h | 4 ++-- target-i386/kvm.c | 4 ++-- ui/vnc-jobs-async.c | 2 +- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/cpus.c b/cpus.c index 0f33945..09ce6fe 100644 --- a/cpus.c +++ b/cpus.c @@ -531,7 +531,7 @@ void qemu_init_vcpu(void *_env) } } -int qemu_cpu_self(void *env) +int qemu_cpu_is_self(void *env) { return 1; } @@ -699,7 +699,7 @@ int qemu_init_main_loop(void) qemu_mutex_init(&qemu_global_mutex); qemu_mutex_lock(&qemu_global_mutex); - qemu_thread_self(&io_thread); + qemu_thread_get_self(&io_thread); return 0; } @@ -714,7 +714,7 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data) { struct qemu_work_item wi; - if (qemu_cpu_self(env)) { + if (qemu_cpu_is_self(env)) { func(data); return; } @@ -808,7 +808,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) int r; qemu_mutex_lock(&qemu_global_mutex); - qemu_thread_self(env->thread); + qemu_thread_get_self(env->thread); r = kvm_init_vcpu(env); if (r < 0) { @@ -845,7 +845,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) CPUState *env = arg; qemu_tcg_init_cpu_signals(); - qemu_thread_self(env->thread); + qemu_thread_get_self(env->thread); /* signal CPU creation */ qemu_mutex_lock(&qemu_global_mutex); @@ -888,14 +888,11 @@ void qemu_cpu_kick_self(void) } } -int qemu_cpu_self(void *_env) +int qemu_cpu_is_self(void *_env) { CPUState *env = _env; - QemuThread this; - qemu_thread_self(&this); - - return qemu_thread_equal(&this, env->thread); + return qemu_thread_is_self(env->thread); } void qemu_mutex_lock_iothread(void) @@ -1023,10 +1020,7 @@ void cpu_stop_current(void) void vm_stop(int reason) { - QemuThread me; - qemu_thread_self(&me); - - if (!qemu_thread_equal(&me, &io_thread)) { + if (!qemu_thread_is_self(&io_thread)) { qemu_system_vmstop_request(reason); /* * FIXME: should not return to device code in case diff --git a/exec.c b/exec.c index d611100..439a6f6 100644 --- a/exec.c +++ b/exec.c @@ -1640,7 +1640,7 @@ void cpu_interrupt(CPUState *env, int mask) * If called from iothread context, wake the target cpu in * case its halted. */ - if (!qemu_cpu_self(env)) { + if (!qemu_cpu_is_self(env)) { qemu_cpu_kick(env); return; } diff --git a/qemu-common.h b/qemu-common.h index 40dad52..958a002 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -289,7 +289,7 @@ void qemu_notify_event(void); /* Unblock cpu */ void qemu_cpu_kick(void *env); void qemu_cpu_kick_self(void); -int qemu_cpu_self(void *env); +int qemu_cpu_is_self(void *env); /* work queue */ struct qemu_work_item { diff --git a/qemu-thread.c b/qemu-thread.c index fbc78fe..e307773 100644 --- a/qemu-thread.c +++ b/qemu-thread.c @@ -176,14 +176,14 @@ void qemu_thread_signal(QemuThread *thread, int sig) error_exit(err, __func__); } -void qemu_thread_self(QemuThread *thread) +void qemu_thread_get_self(QemuThread *thread) { thread->thread = pthread_self(); } -int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2) +int qemu_thread_is_self(QemuThread *thread) { - return pthread_equal(thread1->thread, thread2->thread); + return pthread_equal(pthread_self(), thread->thread); } void qemu_thread_exit(void *retval) diff --git a/qemu-thread.h b/qemu-thread.h index 19bb30c..add97bf 100644 --- a/qemu-thread.h +++ b/qemu-thread.h @@ -37,8 +37,8 @@ void qemu_thread_create(QemuThread *thread, void *(*start_routine)(void*), void *arg); void qemu_thread_signal(QemuThread *thread, int sig); -void qemu_thread_self(QemuThread *thread); -int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2); +void qemu_thread_get_self(QemuThread *thread); +int qemu_thread_is_self(QemuThread *thread); void qemu_thread_exit(void *retval); #endif diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 0aa0a41..1f12cbf 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1355,7 +1355,7 @@ int kvm_arch_put_registers(CPUState *env, int level) { int ret; - assert(cpu_is_stopped(env) || qemu_cpu_self(env)); + assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); ret = kvm_getput_regs(env, 1); if (ret < 0) { @@ -1403,7 +1403,7 @@ int kvm_arch_get_registers(CPUState *env) { int ret; - assert(cpu_is_stopped(env) || qemu_cpu_self(env)); + assert(cpu_is_stopped(env) || qemu_cpu_is_self(env)); ret = kvm_getput_regs(env, 0); if (ret < 0) { diff --git a/ui/vnc-jobs-async.c b/ui/vnc-jobs-async.c index f596247..1dfa6c3 100644 --- a/ui/vnc-jobs-async.c +++ b/ui/vnc-jobs-async.c @@ -303,7 +303,7 @@ static void *vnc_worker_thread(void *arg) { VncJobQueue *queue = arg; - qemu_thread_self(&queue->thread); + qemu_thread_get_self(&queue->thread); while (!vnc_worker_thread_loop(queue)) ; vnc_queue_clear(queue);