From nobody Wed Feb 11 03:24:39 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=1633001177; cv=none; d=zohomail.com; s=zohoarc; b=FgDRD3Ds5JNIfTAKvNnDUEE84eit3SyRL3e1fbEU0K9DLwbPU2FwTsvDkNApwpFqKyJ/YNpOxgEEUPEkTrvmxu5E3jkJ3ZDIaTh3GoXs7eYmwsRsGZh+N8LwqGA2+EFXRVsF7nx9XxdZfhqitxYN2X+/DggI5JIRnU5HXIoFh9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633001177; 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=AV3qCwfv94riAz0CRB9s3RXDsATUEXVxn/f6eSZQlvg=; b=DUC/gLiWe8yHaj5PT4Oyi/Sw8u0Gr2goLq12alWbAIAm48gay21iaVA2KvpQMfQHO96yZ7KmCcUjkse9o2es6QZTPJndriE3WDzRMt/LV5SjufadnaNOAjpyDueV0z3OmrHEmFZs/kSBb1BBKnM8WF4mcoRx0sBtyZTKrW+YmNE= 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 1633001177662629.9902256442049; Thu, 30 Sep 2021 04:26:17 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-O51HvBbFOpW16oernNZDyA-1; Thu, 30 Sep 2021 07:26:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0B651923762; Thu, 30 Sep 2021 11:26:09 +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 847CF60C9F; Thu, 30 Sep 2021 11:26:09 +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 286B64EA3A; Thu, 30 Sep 2021 11:26:09 +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 18UBPG0S021117 for ; Thu, 30 Sep 2021 07:25:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA6EC5F4F0; Thu, 30 Sep 2021 11:25:16 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.194.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F70D5F4EB; Thu, 30 Sep 2021 11:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633001176; 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=AV3qCwfv94riAz0CRB9s3RXDsATUEXVxn/f6eSZQlvg=; b=FyDJ+dRVUB51cYPJRxATD6OIm62EyEs0T/W+bSw64Qt6fIxMkeBvK1TPuyMvTbG/mXc4Dw tMS4dz4P99LeKsTZ4WckhFN3OJnFzkySxe/k1b9gGLC4HviIkL5SoibSsux33fiKDvMmnZ NAvSsRMQK1ed5GYtaxrWdisFRDXRPgU= X-MC-Unique: O51HvBbFOpW16oernNZDyA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v3 4/9] virobject: Introduce virObjectLockGuard Date: Thu, 30 Sep 2021 13:24:54 +0200 Message-Id: <20210930112459.11429-5-twiederh@redhat.com> In-Reply-To: <20210930112459.11429-1-twiederh@redhat.com> References: <20210930112459.11429-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.12 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: 1633001179716100003 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 --- 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 f41674781d..733e40384e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2947,6 +2947,7 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLockGuard; virObjectNew; virObjectRef; virObjectRWLockableNew; diff --git a/src/util/virobject.c b/src/util/virobject.c index 3412985b79..4812b79d56 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 virLockGuardNew(&obj->lock); +} + + /** * virObjectLock: * @anyobj: any instance of virObjectLockable diff --git a/src/util/virobject.h b/src/util/virobject.h index 1e34c77744..0c9cbea726 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