From patchwork Fri Dec 30 00:01:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 637837 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3180983pvb; Thu, 29 Dec 2022 16:13:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXt5cRuMLyH+tQja8iDIwzVdjXDVFDXjuy1U2JjEKFoACzM/7HirxjdiM0WCsszgLXTDjpeX X-Received: by 2002:a05:6214:10e8:b0:4c7:8271:d0fa with SMTP id q8-20020a05621410e800b004c78271d0famr54069738qvt.24.1672359232247; Thu, 29 Dec 2022 16:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672359232; cv=none; d=google.com; s=arc-20160816; b=MiFKAJWXF5Nk8vkKM+zTx2OnOWwS8VciVR9shNLlrf0VodBLqV2webkAo8QTu3l2fP 9zlTsaPQjCTg5gx8NQi7S6QNzOtBIZvHmWmTIU4SULfxqIQ1Qur7E9VHwFWut+pqAEzj xtxoYNCnHIYgrzBCZJAAlwHFPQDfBb4fsPmp9vvoxiUEDepwxJ5uyMJXuxfuicR8jpQN 32R306r0sEHlp0c8ptyVAaKr3LZ6NlT3GIHfKaX1egp5B5LtG2i+j3qCN53U4Jq1jvid UKIKr64AD4/VUHvE9Cw7pucWm9PBxlL2RykYwXJFQpptVyc91XdGB/YHAzcJ1hOSpC4q EJhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xe4xTZh/olelEWsm0lJjRBAP0V+vxyo3x0yWKfVII3Q=; b=pBb/LbGSYhm6gkrtiO3M7EOSEXCyzj4fK0cEH6EhyraZJNRepYfbH0hPB+usq6OPYm IRSIMaDSbzVtCU++4baoZt4OeOZEvfiuYodiHqmBbg9phmMhGtvE0VAkAogHkIPqZnz5 lBhKrKcs5fqo5oqKNmqaWbG36yvUDa5kPKnz4AFqUB3Onfs2IhmIvS3LLmgSHZmjSBmI QHq//J5/mNaqfWz4QUydW9cuwH4VX1lMYI9mJrOekUWRowUauvoCV78khG6P8E1MiSah Lq6kNmg+MRIHPgGoOA8FXzbvMNDlP3d2DYRCZ1gMLbu8irsx4px6f99b0i1zvqvFMqdP I9rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=InX3Bww5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kc4-20020a056214410400b00529831bf68fsi9075531qvb.199.2022.12.29.16.13.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Dec 2022 16:13:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=InX3Bww5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pB2r5-0002yL-09; Thu, 29 Dec 2022 19:02:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pB2r2-0002xM-R6 for qemu-devel@nongnu.org; Thu, 29 Dec 2022 19:02:33 -0500 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pB2qz-0002fO-KC for qemu-devel@nongnu.org; Thu, 29 Dec 2022 19:02:32 -0500 Received: by mail-pj1-x1031.google.com with SMTP id p4so20796358pjk.2 for ; Thu, 29 Dec 2022 16:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xe4xTZh/olelEWsm0lJjRBAP0V+vxyo3x0yWKfVII3Q=; b=InX3Bww5FTo6olEtvtEQ3RMkkrfThUjDRB+E0TA+5r0J1m+uaS6rex0MZ9tBn3OqpE g+XgaagGG+QoGaOTsigKaQfzH5deXQbYwFH0fFB7RFK1YH1Le1Ls3qzzr4czRQ279pBq UmcZDbawX7dwTEuI8A8LpCxUJUKGcaXsbtiJjNxd8s1BNhsF8ZeX1l78kdL/g6COvnkJ ul30SJCiVc0BV4mgB1ybU/8FD5JtNho7Y5khSsUKkLANejykB4WxpX/D533+1I1UUYgB HZ8xf9izclQVDnHKSJxnFaKsGMQxD9JN0XYBWyiaWleI5pwOrND9yojuRSp0T1tuQ4uo TfZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xe4xTZh/olelEWsm0lJjRBAP0V+vxyo3x0yWKfVII3Q=; b=wLZhhsq95IQ1iHI+GiP4C68TTUV9SxW2KuFjR3l0GPhUg5bMyXivbHj7DMUctsk7x3 IFk47pv0bhFP07/4dfpj2VDu+9fMjBjfUe10vys6vQz4pM66QJVQlsnKD0pMJdURezDL qI8RjikiAIIplY4o6G1nj5781+pPW8GLWk6fco3wz+Ynq3Sc29B+2GCTnSziitW2C8yt 1vgQWU1n4+s23Tlm/gEmyKUGe7dbHtCjUQp/+Blm2nm7qrhb3qq993Y4IJ1Y2vywN38Y jEKUVIa5EULdZs0YcWXJbzv1nI+o3/RQweiLYo8qU0EwoLgSzOwZ21bkOI7hVetAoDzM g4qA== X-Gm-Message-State: AFqh2krvz/3sz6+eFuy2OoWI6IWBIGy1569UnDfAnNeZu8PkU2ONJ9Y7 3tGepWV5bexpdvQeXbWrn+FBa4mUMOdlQiV4 X-Received: by 2002:a17:902:ccc1:b0:189:8002:5f59 with SMTP id z1-20020a170902ccc100b0018980025f59mr57457991ple.57.1672358547776; Thu, 29 Dec 2022 16:02:27 -0800 (PST) Received: from stoup.. (76-14-210-194.or.wavecable.com. [76.14.210.194]) by smtp.gmail.com with ESMTPSA id j14-20020a170903028e00b00192849e1d0asm7343953plr.116.2022.12.29.16.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 16:02:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 05/47] qemu/main-loop: Introduce QEMU_IOTHREAD_LOCK_GUARD Date: Thu, 29 Dec 2022 16:01:39 -0800 Message-Id: <20221230000221.2764875-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221230000221.2764875-1-richard.henderson@linaro.org> References: <20221230000221.2764875-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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, 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-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Create a wrapper for locking/unlocking the iothread lock. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/qemu/main-loop.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index 3c9a9a982d..c25f390696 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -343,6 +343,35 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line); */ void qemu_mutex_unlock_iothread(void); +/** + * QEMU_IOTHREAD_LOCK_GUARD + * + * Wrap a block of code in a conditional qemu_mutex_{lock,unlock}_iothread. + */ +typedef struct IOThreadLockAuto IOThreadLockAuto; + +static inline IOThreadLockAuto *qemu_iothread_auto_lock(const char *file, + int line) +{ + if (qemu_mutex_iothread_locked()) { + return NULL; + } + qemu_mutex_lock_iothread_impl(file, line); + /* Anything non-NULL causes the cleanup function to be called */ + return (IOThreadLockAuto *)(uintptr_t)1; +} + +static inline void qemu_iothread_auto_unlock(IOThreadLockAuto *l) +{ + qemu_mutex_unlock_iothread(); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(IOThreadLockAuto, qemu_iothread_auto_unlock) + +#define QEMU_IOTHREAD_LOCK_GUARD() \ + g_autoptr(IOThreadLockAuto) _iothread_lock_auto __attribute__((unused)) \ + = qemu_iothread_auto_lock(__FILE__, __LINE__) + /* * qemu_cond_wait_iothread: Wait on condition for the main loop mutex *