From nobody Mon Feb 9 23:15:06 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=1643721657; cv=none; d=zohomail.com; s=zohoarc; b=Ull0aJYxBkFx6nsUHejbs+gUttBDUFI6TBtygmVCFKaWH4hV3Hq4F2IxwCmx7PwFGy1WPxprFhxoUn2yzIGNdLIQ52eJfBr0+qx8CUkntIwvKN7TURjPhDpRJJ1Xf+l0VJWdlnYIaEV7OJNscNdavCz38BSMdRkIApOGVgK44fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643721657; 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=ghYMZVzFXr3zu5BJJIxUHGWCLCfaR71vE3jMtTzsKBM=; b=mcIRsE/XaekARlGgjQL6dHyP0YIQ7CHZRy5raQKvXHnkliqT14iyHX1Dlao+P9UUOdZqspDN+vELHvnRfE0lpZlqfTda/pk5LohqDbSb2Tr2gKZHSvpkE9zeaidKG+wHPgy6DeGzhfxEiz0PKxLVtNNPQV7Imn6UCFxC6Tr+81c= 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 1643721657005681.5271519685648; Tue, 1 Feb 2022 05:20:57 -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-18-M_gAnKqTO8agcHC78ByVog-1; Tue, 01 Feb 2022 08:20:52 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E02B48519E4; Tue, 1 Feb 2022 13:20:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB78C7D716; Tue, 1 Feb 2022 13:20: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 6B70D4A7C8; Tue, 1 Feb 2022 13:20:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 211DKNQo007445 for ; Tue, 1 Feb 2022 08:20:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8A0ED10A48B3; Tue, 1 Feb 2022 13:20:23 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.195.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id D44CC10A48AC; Tue, 1 Feb 2022 13:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643721656; 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=ghYMZVzFXr3zu5BJJIxUHGWCLCfaR71vE3jMtTzsKBM=; b=JAD4HaWjQuUXyvrCNRvvpfV242o95l3mxEsQjP5HGL9mE54ProIUOM4ygUhN96Owo6t1QZ 0t1dh93wu0xYC9bpZzddnajI4H+wp3iDAoyHiQLR+PC2vaQ2XoPIXg2VlkXg2tnebjOMNN iowvqEVc/Ko13fkKluRwIpnBzJIC3CE= X-MC-Unique: M_gAnKqTO8agcHC78ByVog-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v5 4/9] virobject: Introduce virObjectLockGuard Date: Tue, 1 Feb 2022 14:20:12 +0100 Message-Id: <20220201132017.53963-5-twiederh@redhat.com> In-Reply-To: <20220201132017.53963-1-twiederh@redhat.com> References: <20220201132017.53963-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.13 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: 1643721660467100001 Content-Type: text/plain; charset="utf-8" Typical usage: void foobar(virObjectLockable *obj) { VIR_LOCK_GUARD lock =3D virObjectLockGuard(obj); /* `obj` is locked, and released automatically on scope exit */ ... } Signed-off-by: Tim Wiederhake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 1 + src/util/virobject.c | 16 ++++++++++++++++ src/util/virobject.h | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5da9874e17..9bc3d9530b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2956,6 +2956,7 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLockGuard; virObjectNew; virObjectRef; virObjectRWLockableNew; diff --git a/src/util/virobject.c b/src/util/virobject.c index 588b41802c..74cc84205e 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -426,6 +426,22 @@ virObjectGetRWLockableObj(void *anyobj) } =20 =20 +/** + * virObjectLockGuard: + * @anyobj: any instance of virObjectLockable + * + * Acquire a lock on @anyobj that will be managed by the virLockGuard obje= ct + * returned to the caller. + */ +virLockGuard +virObjectLockGuard(void *anyobj) +{ + virObjectLockable *obj =3D virObjectGetLockableObj(anyobj); + + return virLockGuardLock(&obj->lock); +} + + /** * virObjectLock: * @anyobj: any instance of virObjectLockable diff --git a/src/util/virobject.h b/src/util/virobject.h index 1e34c77744..dc1ce66a4f 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -118,6 +118,10 @@ void * virObjectRWLockableNew(virClass *klass) ATTRIBUTE_NONNULL(1); =20 +virLockGuard +virObjectLockGuard(void *lockableobj) + ATTRIBUTE_NONNULL(1); + void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); --=20 2.31.1