From nobody Tue Feb 10 08:28:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1643364020; cv=none; d=zohomail.com; s=zohoarc; b=mB4/T2QaHobAgDM0PO0NSqKWgWQzmwV2zjNJS3IZjtij2124JEShhM5UQ8b6L83K8Eb7ozpYtU2EfSopZKrdBmr0DyDhnqvhwvAOkC169fVB5VViFV61be/dNzyc1zH3KXrfbQvEckHXIHr6Eldjq8/46ZoVRv2bJ06rMB6mTcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643364020; h=Content-Type: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=9h3ofOmdp9yfmFIt1hagMHMWlAf7WnMD2o+Rm5ckrls=; b=YUmfZ1vFPkVRQPG0GdHeA0V+2vC01idGFQnO+j5dUeq5NEyJ/LU6Tkshwn+HQZE2WL7rCcXU4tTcXNsUlmvcgHOvN++2tDGmTKja3SVwDvxMxQsON/pVVwQHLV61tsChp4pQbUR2pwkPezl5Noe9wUJZoKfqAPyFZXwKHB06SOY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1643364020237221.701400601944; Fri, 28 Jan 2022 02:00:20 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-668-B_IjkWenME-nIzeQTOJ2Xg-1; Fri, 28 Jan 2022 05:00:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E97D1098256; Fri, 28 Jan 2022 09:59:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2917B7B6D8; Fri, 28 Jan 2022 09:59:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B33CC1809CB8; Fri, 28 Jan 2022 09:59:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20S9xi8U031734 for ; Fri, 28 Jan 2022 04:59:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 12F6F74EAE; Fri, 28 Jan 2022 09:59:44 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.194.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 109A0703B6; Fri, 28 Jan 2022 09:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643364019; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9h3ofOmdp9yfmFIt1hagMHMWlAf7WnMD2o+Rm5ckrls=; b=T89zJOp8IyxccnrMowndhxnc4zG3OQXkcFpXIelWl0jbj6lyRZN2EOaWpGnI7c70R3hKdQ XiWhyKtC6yC6X3Cgt7PPxmqLB+EJXbrY0uTVQt1bSDTNLlGeD2wZqwJA92Oib55UuoWfKp vy5wotECqDy8/QFyxkCc/P8FReLiqOA= X-MC-Unique: B_IjkWenME-nIzeQTOJ2Xg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v4 3/9] virthread: Introduce VIR_WITH_MUTEX_LOCK_GUARD Date: Fri, 28 Jan 2022 10:59:16 +0100 Message-Id: <20220128095922.17782-4-twiederh@redhat.com> In-Reply-To: <20220128095922.17782-1-twiederh@redhat.com> References: <20220128095922.17782-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1643364021489100003 Content-Type: text/plain; charset="utf-8" Modeled after "WITH_QEMU_LOCK_GUARD" (see qemu's include/qemu/lockable.h). Uses "__LINE__" instead of "__COUNTER__", as the latter is a GNU extension. See comment for typical usage. Signed-off-by: Tim Wiederhake --- src/util/virthread.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/virthread.h b/src/util/virthread.h index 6cdaf2820e..da17780908 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -209,3 +209,23 @@ int virThreadLocalSet(virThreadLocal *l, void*) G_GNUC= _WARN_UNUSED_RESULT; return 0; \ } \ struct classname ## EatSemicolon + +/** + * VIR_WITH_MUTEX_LOCK_GUARD: + * + * This macro defines a lock scope such that entering the scope takes the = lock + * and leaving the scope releases the lock. Return statements are allowed + * within the scope and release the lock. Break and continue statements le= ave + * the scope early and release the lock. + * + * virMutex *mutex =3D ...; + * + * VIR_WITH_MUTEX_LOCK_GUARD(mutex) { + * // `mutex` is locked, and released automatically on scope exit + * ... + * } + */ +#define VIR_WITH_MUTEX_LOCK_GUARD(m) \ + for (g_auto(virLockGuard) CONCAT(var, __LINE__) =3D virLockGuardLock(m= ); \ + CONCAT(var, __LINE__).mutex; \ + CONCAT(var, __LINE__).mutex =3D (virLockGuardUnlock(& CONCAT(var,= __LINE__)), NULL)) --=20 2.31.1