From: Paolo Bonzini Subject: [PATCH v3 uq/master 22/22] add Win32 IPI service Date: Mon, 28 Feb 2011 10:10:24 +0100 Message-ID: <1298884224-19734-23-git-send-email-pbonzini@redhat.com> References: <1298884224-19734-1-git-send-email-pbonzini@redhat.com> Cc: kvm@vger.kernel.org, aurelien@aurel32.net, blauwirbel@gmail.com, jan.kiszka@siemes.com, mtosatti@redhat.com To: qemu-devel@nongnu.org Return-path: Received: from mail-gx0-f174.google.com ([209.85.161.174]:36202 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753078Ab1B1JLa (ORCPT ); Mon, 28 Feb 2011 04:11:30 -0500 Received: by mail-gx0-f174.google.com with SMTP id 8so1438591gxk.19 for ; Mon, 28 Feb 2011 01:11:30 -0800 (PST) In-Reply-To: <1298884224-19734-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Paolo Bonzini --- cpus.c | 25 ++++++++++++++++++++++--- qemu-thread-posix.c | 9 --------- qemu-thread-posix.h | 1 - 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cpus.c b/cpus.c index 7559a02..077729c 100644 --- a/cpus.c +++ b/cpus.c @@ -854,13 +854,32 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) return NULL; } +static void qemu_cpu_kick_thread(CPUState *env) +{ +#ifndef _WIN32 + int err; + + err = pthread_kill(env->thread->thread, SIG_IPI); + if (err) { + fprintf(stderr, "qemu:%s: %s", __func__, strerror(err)); + exit(1); + } +#else /* _WIN32 */ + if (!qemu_cpu_is_self(env)) { + SuspendThread(env->thread->thread); + cpu_signal(0); + ResumeThread(env->thread->thread); + } +#endif +} + void qemu_cpu_kick(void *_env) { CPUState *env = _env; qemu_cond_broadcast(env->halt_cond); if (!env->thread_kicked) { - qemu_thread_signal(env->thread, SIG_IPI); + qemu_cpu_kick_thread(env); env->thread_kicked = true; } } @@ -871,7 +890,7 @@ void qemu_cpu_kick_self(void) assert(cpu_single_env); if (!cpu_single_env->thread_kicked) { - qemu_thread_signal(cpu_single_env->thread, SIG_IPI); + qemu_cpu_kick_thread(cpu_single_env); cpu_single_env->thread_kicked = true; } #else @@ -893,7 +912,7 @@ void qemu_mutex_lock_iothread(void) } else { qemu_mutex_lock(&qemu_fair_mutex); if (qemu_mutex_trylock(&qemu_global_mutex)) { - qemu_thread_signal(tcg_cpu_thread, SIG_IPI); + qemu_cpu_kick_thread(first_cpu); qemu_mutex_lock(&qemu_global_mutex); } qemu_mutex_unlock(&qemu_fair_mutex); diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c index a4c6e25..9cceda7 100644 --- a/qemu-thread-posix.c +++ b/qemu-thread-posix.c @@ -186,15 +186,6 @@ void qemu_thread_create(QemuThread *thread, pthread_sigmask(SIG_SETMASK, &oldset, NULL); } -void qemu_thread_signal(QemuThread *thread, int sig) -{ - int err; - - err = pthread_kill(thread->thread, sig); - if (err) - error_exit(err, __func__); -} - void qemu_thread_get_self(QemuThread *thread) { thread->thread = pthread_self(); diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h index 11978db..35e0a8b 100644 --- a/qemu-thread-posix.h +++ b/qemu-thread-posix.h @@ -15,5 +15,4 @@ struct QemuThread { pthread_t thread; }; -void qemu_thread_signal(QemuThread *thread, int sig); #endif -- 1.7.4