From nobody Tue Nov 4 15:26:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530217365108756.2174987262695; Thu, 28 Jun 2018 13:22:45 -0700 (PDT) Received: from localhost ([::1]:38370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdRC-0004Qs-7U for importer@patchew.org; Thu, 28 Jun 2018 16:22:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdAX-0007BD-Vi for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdAW-0000JL-D5 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:29 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:54422) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdAV-0000HU-IF for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:28 -0400 Received: by mail-wm0-x22c.google.com with SMTP id i139-v6so10967516wmf.4 for ; Thu, 28 Jun 2018 13:05:27 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.05.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=owCGhLAFULbHajhHqpQGqRHMpNzLB41GNsGhlkCIbl0=; b=jhZ8/NpFCRDzlJkkZj2J6B7l0CXALlWOheqvGbfqduT3HMYmjrVH6wgSLQD9NQgVD8 qlojIio9kLLvTim0vUhCVDGOMW4KkwVnMCQqHkGKkifjlu0UukHkxEDL0XmMrXeOetF6 emOLRayZ20ScW01LGAMo2cV0QdfL7iF3Gadm61jyl95AYwHRHSDlSeVydbH8cvNBx4o4 Kr9rh0LO8oqT+USBfk4k+UjBNUQWCGPnZzGiBiKV1iz1ch+k2xaI6UYZ2LiOR4Bq1rCn e5YkFdsaFMaOblK5+a9eS1zLLSee0SedvPFO4BYa60KUyfoDpb/DkZGOj8YPAjqPaeRX 25Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=owCGhLAFULbHajhHqpQGqRHMpNzLB41GNsGhlkCIbl0=; b=o+JjDsH1rmTjJie81ekNu/+0OHVvMZZBeojzC+RR44NyYVqYKDRvBsjm5aKlEuZFSB cXIZkYjX2LHOrxVV4nSt2Lei9UqlcaQvZMeqOOKKF4/kbVRAOx7k8cnE97O1eQvu27LJ yX7mRhoSNMJhmBzomGvlrudkAlTZuqdrrYjtvgOwYcJgNoXnPGAnIVexOE/lHe845f8H jgt87OdfvOw/PP7oSBosbY1x7xXzw45ZD+QTXdkTp9oeKX2AvLNewOoUV6UgyaITuGwK 2XJSLIYqqrdeC89+TijpjWyrDtJf/v0zC6RVzv/DL6RNcHJW/Xnju15HKNRY4n5MLpCJ E6gg== X-Gm-Message-State: APt69E2dD6MN1QvJmgiItj+Kkxw4BtiQGAZ91sCSCAG34iaYIVEYC6JG SdD8rGUTWldQO3lT8/poXK0WmBVt X-Google-Smtp-Source: AAOMgpcK/Gfk+71aeRd6VBPaSeoGqI0PM7NMfzh6zxuIS1pB7yxm8eLiuFVqLQyZMGwWOWhhUR3ccA== X-Received: by 2002:a1c:45db:: with SMTP id l88-v6mr8802935wmi.19.1530216326260; Thu, 28 Jun 2018 13:05:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:04:22 +0200 Message-Id: <1530216310-52873-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22c Subject: [Qemu-devel] [PULL 12/60] qemu-thread: introduce qemu-thread-common.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu Introduce some hooks for the shared part of qemu thread between POSIX and Windows implementations. Note that in qemu_mutex_unlock_impl() we moved the call before unlock operation which should make more sense. And we don't need qemu_mutex_post_unlock() hook. Put all these shared hooks into the header files. It should be internal to qemu-thread but not for qemu-thread users, hence put into util/ directory. Reviewed-by: Emilio G. Cota Signed-off-by: Peter Xu Message-Id: <20180425025459.5258-3-peterx@redhat.com> Signed-off-by: Paolo Bonzini --- util/qemu-thread-common.h | 43 +++++++++++++++++++++++++++++++++++++++++++ util/qemu-thread-posix.c | 19 ++++++++----------- util/qemu-thread-win32.c | 17 ++++++++--------- 3 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 util/qemu-thread-common.h diff --git a/util/qemu-thread-common.h b/util/qemu-thread-common.h new file mode 100644 index 0000000..d329208 --- /dev/null +++ b/util/qemu-thread-common.h @@ -0,0 +1,43 @@ +/* + * Common qemu-thread implementation header file. + * + * Copyright Red Hat, Inc. 2018 + * + * Authors: + * Peter Xu , + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_THREAD_COMMON_H +#define QEMU_THREAD_COMMON_H + +#include "qemu/typedefs.h" +#include "qemu/thread.h" +#include "trace.h" + +static inline void qemu_mutex_post_init(QemuMutex *mutex) +{ + mutex->initialized =3D true; +} + +static inline void qemu_mutex_pre_lock(QemuMutex *mutex, + const char *file, int line) +{ + trace_qemu_mutex_lock(mutex, file, line); +} + +static inline void qemu_mutex_post_lock(QemuMutex *mutex, + const char *file, int line) +{ + trace_qemu_mutex_locked(mutex, file, line); +} + +static inline void qemu_mutex_pre_unlock(QemuMutex *mutex, + const char *file, int line) +{ + trace_qemu_mutex_unlock(mutex, file, line); +} + +#endif diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index a1c34ba..dfa66ff 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -14,7 +14,7 @@ #include "qemu/thread.h" #include "qemu/atomic.h" #include "qemu/notify.h" -#include "trace.h" +#include "qemu-thread-common.h" =20 static bool name_threads; =20 @@ -43,7 +43,7 @@ void qemu_mutex_init(QemuMutex *mutex) err =3D pthread_mutex_init(&mutex->lock, NULL); if (err) error_exit(err, __func__); - mutex->initialized =3D true; + qemu_mutex_post_init(mutex); } =20 void qemu_mutex_destroy(QemuMutex *mutex) @@ -62,13 +62,11 @@ void qemu_mutex_lock_impl(QemuMutex *mutex, const char = *file, const int line) int err; =20 assert(mutex->initialized); - trace_qemu_mutex_lock(mutex, file, line); - + qemu_mutex_pre_lock(mutex, file, line); err =3D pthread_mutex_lock(&mutex->lock); if (err) error_exit(err, __func__); - - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); } =20 int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int = line) @@ -78,7 +76,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char = *file, const int line) assert(mutex->initialized); err =3D pthread_mutex_trylock(&mutex->lock); if (err =3D=3D 0) { - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); return 0; } if (err !=3D EBUSY) { @@ -92,11 +90,10 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex, const cha= r *file, const int line) int err; =20 assert(mutex->initialized); + qemu_mutex_pre_unlock(mutex, file, line); err =3D pthread_mutex_unlock(&mutex->lock); if (err) error_exit(err, __func__); - - trace_qemu_mutex_unlock(mutex, file, line); } =20 void qemu_rec_mutex_init(QemuRecMutex *mutex) @@ -160,9 +157,9 @@ void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mut= ex, const char *file, con int err; =20 assert(cond->initialized); - trace_qemu_mutex_unlock(mutex, file, line); + qemu_mutex_pre_unlock(mutex, file, line); err =3D pthread_cond_wait(&cond->cond, &mutex->lock); - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); if (err) error_exit(err, __func__); } diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index ab60c0d..b303188 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -19,7 +19,7 @@ #include "qemu-common.h" #include "qemu/thread.h" #include "qemu/notify.h" -#include "trace.h" +#include "qemu-thread-common.h" #include =20 static bool name_threads; @@ -46,7 +46,7 @@ static void error_exit(int err, const char *msg) void qemu_mutex_init(QemuMutex *mutex) { InitializeSRWLock(&mutex->lock); - mutex->initialized =3D true; + qemu_mutex_post_init(mutex); } =20 void qemu_mutex_destroy(QemuMutex *mutex) @@ -59,10 +59,9 @@ void qemu_mutex_destroy(QemuMutex *mutex) void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int li= ne) { assert(mutex->initialized); - trace_qemu_mutex_lock(mutex, file, line); - + qemu_mutex_pre_lock(mutex, file, line); AcquireSRWLockExclusive(&mutex->lock); - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); } =20 int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int = line) @@ -72,7 +71,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char = *file, const int line) assert(mutex->initialized); owned =3D TryAcquireSRWLockExclusive(&mutex->lock); if (owned) { - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); return 0; } return -EBUSY; @@ -81,7 +80,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char = *file, const int line) void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int = line) { assert(mutex->initialized); - trace_qemu_mutex_unlock(mutex, file, line); + qemu_mutex_pre_unlock(mutex, file, line); ReleaseSRWLockExclusive(&mutex->lock); } =20 @@ -145,9 +144,9 @@ void qemu_cond_broadcast(QemuCond *cond) void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *fil= e, const int line) { assert(cond->initialized); - trace_qemu_mutex_unlock(mutex, file, line); + qemu_mutex_pre_unlock(mutex, file, line); SleepConditionVariableSRW(&cond->var, &mutex->lock, INFINITE, 0); - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); } =20 void qemu_sem_init(QemuSemaphore *sem, int init) --=20 1.8.3.1