From nobody Mon Feb 9 08:11:27 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1615454924; cv=none; d=zohomail.com; s=zohoarc; b=ZuNtIpC264EVIF8hGHu2vZkcYsTM45tIrTzeLSqg+dASA8ng0WHg1D2oFlfcQD1qUbqd6pxYC28na0s1D90rsjrEiechuQccVGUJqfaiAjAGqM2axaxpI8uMx1AHtqnPmTUMLdD1d9jxC4kDGbjQZYsdim6OsYlGv2woBYIyHfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615454924; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UF2uIEk2a+ZLtiqF+PRF7HpxKroPVBJ9bM3hn+fhcM0=; b=PK/a8zd003h62bajQ8fuWhSwWOXuDBHSP2irRPx4/yrzQjuzHPRwwQD04Hvw/QoXDI4nz3STlrM3wUdaP77hGl1e5HguexuGHL442WHWF366a3id3ZK1KFUrbUd/spidZ1GexBHLUQmeF1E+vC71xXP0wxWSc7beRsIpXzd3hjI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615454924270294.5143182037058; Thu, 11 Mar 2021 01:28:44 -0800 (PST) Received: from localhost ([::1]:40872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKHcZ-0002mn-91 for importer@patchew.org; Thu, 11 Mar 2021 04:28:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKBnq-0001OC-Sk for qemu-devel@nongnu.org; Wed, 10 Mar 2021 22:15:58 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:53802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lKBno-0000i3-V7 for qemu-devel@nongnu.org; Wed, 10 Mar 2021 22:15:58 -0500 Received: by mail-wm1-x32f.google.com with SMTP id g20so406514wmk.3 for ; Wed, 10 Mar 2021 19:15:56 -0800 (PST) Received: from localhost.localdomain ([197.61.47.225]) by smtp.googlemail.com with ESMTPSA id o188sm1450416wme.7.2021.03.10.19.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 19:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UF2uIEk2a+ZLtiqF+PRF7HpxKroPVBJ9bM3hn+fhcM0=; b=p7r8dUNkzKckPl+pLRABtoFa1fJbcoI/OZjUiydMahx/Z2ZbFuX+0b1z5GGi9+ADur m0wfbB5GghB96y9fHussnLVzTpe+97yhaxuaZyb74b6O0dCVp+Pt4rsgW+dPS8FA7Wjg ncm6bmwX6XWq2e+lnoILOpzaPQXjp3nDkwyIzM6eQiSSxOOI5//XDStbmGqPuepqivyv uDvkazWvMtaluVTo8Mi3XzvQb5VKkLhlc4FDDfWXeJHrdBabXE5GnBql5zz12lOHdfMF 1B5jzu+OPAY7IXo/Nn9hnD12npKmAceUvheXMeXHJH00SIjc/VEsmg+QECON2v6UobZj pzFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UF2uIEk2a+ZLtiqF+PRF7HpxKroPVBJ9bM3hn+fhcM0=; b=Ot7H326fm97vNQ2WphSpY/LmuaBLJuJ65kq2TNKqr2BKIA6vCqdFujscAMAoqMrCjE UpkviehI737VAYw3KAmJl8keJgJpD4sz29d3dMdYTlvbq6YctcyA5yiuJChlt58FyM1x 9EEHYGuE+H/NeDkJwu6L9lmqyGEQuNlBMbCURRINMV+X/6kxSTMIUhSQyAFWbJeeZWzU wq68w7IupVRmHbqIyemgzp+NsP87nYwnSXN2sfBvb4lejQpvkdpKN1o2p7HQDdOp/dwx +0U5P7dW8xxCovnzowtl5CvPfRV6sBxinuYLFtRwH/jdLvXs6jX2oawMHF/BxHqFCjJ7 5jMQ== X-Gm-Message-State: AOAM531RZGA5vpSCjoly05kLUVONfTupCKjSIbHSy52nh0jwNZe9sK5/ aQrj4STGfShH0xTS80/nOJIsOfWcpb8TrLPi8xQ= X-Google-Smtp-Source: ABdhPJzkMbMUsyT4HZ2GJfhA/mkSxRJne8Pg2hcHgamvknhMnPlMaW/4QY6emjnYWr1gKt2fhEswhg== X-Received: by 2002:a1c:a916:: with SMTP id s22mr6247078wme.82.1615432555262; Wed, 10 Mar 2021 19:15:55 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 5/9] monitor: Replaced qemu_mutex_lock calls with QEMU_LOCK_GUARD Date: Thu, 11 Mar 2021 05:15:34 +0200 Message-Id: <20210311031538.5325-6-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210311031538.5325-1-ma.mandourr@gmail.com> References: <20210311031538.5325-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 11 Mar 2021 04:24:53 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , Markus Armbruster , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Removed various qemu_mutex_lock and their respective qemu_mutex_unlock calls and used lock guard macros (QEMU_LOCK_GUARD and WITH_QEMU_LOCK_GUARD). This simplifies the code by eliminating qemu_mutex_unlock calls. Signed-off-by: Mahmoud Mandour Reviewed-by: Dr. David Alan Gilbert --- monitor/monitor.c | 8 ++------ monitor/qmp.c | 51 ++++++++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index e94f532cf5..640496e562 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -349,7 +349,7 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) evconf =3D &monitor_qapi_event_conf[event]; trace_monitor_protocol_event_queue(event, qdict, evconf->rate); =20 - qemu_mutex_lock(&monitor_lock); + QEMU_LOCK_GUARD(&monitor_lock); =20 if (!evconf->rate) { /* Unthrottled event */ @@ -391,8 +391,6 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) timer_mod_ns(evstate->timer, now + evconf->rate); } } - - qemu_mutex_unlock(&monitor_lock); } =20 void qapi_event_emit(QAPIEvent event, QDict *qdict) @@ -447,7 +445,7 @@ static void monitor_qapi_event_handler(void *opaque) MonitorQAPIEventConf *evconf =3D &monitor_qapi_event_conf[evstate->eve= nt]; =20 trace_monitor_protocol_event_handler(evstate->event, evstate->qdict); - qemu_mutex_lock(&monitor_lock); + QEMU_LOCK_GUARD(&monitor_lock); =20 if (evstate->qdict) { int64_t now =3D qemu_clock_get_ns(monitor_get_event_clock()); @@ -462,8 +460,6 @@ static void monitor_qapi_event_handler(void *opaque) timer_free(evstate->timer); g_free(evstate); } - - qemu_mutex_unlock(&monitor_lock); } =20 static unsigned int qapi_event_throttle_hash(const void *key) diff --git a/monitor/qmp.c b/monitor/qmp.c index 2326bd7f9b..2b0308f933 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -76,7 +76,7 @@ static void monitor_qmp_cleanup_req_queue_locked(MonitorQ= MP *mon) =20 static void monitor_qmp_cleanup_queue_and_resume(MonitorQMP *mon) { - qemu_mutex_lock(&mon->qmp_queue_lock); + QEMU_LOCK_GUARD(&mon->qmp_queue_lock); =20 /* * Same condition as in monitor_qmp_dispatcher_co(), but before @@ -103,7 +103,6 @@ static void monitor_qmp_cleanup_queue_and_resume(Monito= rQMP *mon) monitor_resume(&mon->common); } =20 - qemu_mutex_unlock(&mon->qmp_queue_lock); } =20 void qmp_send_response(MonitorQMP *mon, const QDict *rsp) @@ -179,7 +178,7 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_lo= ck(void) Monitor *mon; MonitorQMP *qmp_mon; =20 - qemu_mutex_lock(&monitor_lock); + QEMU_LOCK_GUARD(&monitor_lock); =20 QTAILQ_FOREACH(mon, &mon_list, entry) { if (!monitor_is_qmp(mon)) { @@ -205,8 +204,6 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_lo= ck(void) QTAILQ_INSERT_TAIL(&mon_list, mon, entry); } =20 - qemu_mutex_unlock(&monitor_lock); - return req_obj; } =20 @@ -376,30 +373,30 @@ static void handle_qmp_command(void *opaque, QObject = *req, Error *err) req_obj->err =3D err; =20 /* Protect qmp_requests and fetching its length. */ - qemu_mutex_lock(&mon->qmp_queue_lock); + WITH_QEMU_LOCK_GUARD(&mon->qmp_queue_lock) { =20 - /* - * Suspend the monitor when we can't queue more requests after - * this one. Dequeuing in monitor_qmp_dispatcher_co() or - * monitor_qmp_cleanup_queue_and_resume() will resume it. - * Note that when OOB is disabled, we queue at most one command, - * for backward compatibility. - */ - if (!qmp_oob_enabled(mon) || - mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1) { - monitor_suspend(&mon->common); - } + /* + * Suspend the monitor when we can't queue more requests after + * this one. Dequeuing in monitor_qmp_dispatcher_co() or + * monitor_qmp_cleanup_queue_and_resume() will resume it. + * Note that when OOB is disabled, we queue at most one command, + * for backward compatibility. + */ + if (!qmp_oob_enabled(mon) || + mon->qmp_requests->length =3D=3D QMP_REQ_QUEUE_LEN_MAX - 1) { + monitor_suspend(&mon->common); + } =20 - /* - * Put the request to the end of queue so that requests will be - * handled in time order. Ownership for req_obj, req, - * etc. will be delivered to the handler side. - */ - trace_monitor_qmp_in_band_enqueue(req_obj, mon, - mon->qmp_requests->length); - assert(mon->qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX); - g_queue_push_tail(mon->qmp_requests, req_obj); - qemu_mutex_unlock(&mon->qmp_queue_lock); + /* + * Put the request to the end of queue so that requests will be + * handled in time order. Ownership for req_obj, req, + * etc. will be delivered to the handler side. + */ + trace_monitor_qmp_in_band_enqueue(req_obj, mon, + mon->qmp_requests->length); + assert(mon->qmp_requests->length < QMP_REQ_QUEUE_LEN_MAX); + g_queue_push_tail(mon->qmp_requests, req_obj); + } =20 /* Kick the dispatcher routine */ if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) { --=20 2.25.1