From nobody Mon Apr 29 07:51:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508866518261367.1500557678985; Tue, 24 Oct 2017 10:35:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7AFC3C04B927; Tue, 24 Oct 2017 17:35:16 +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 191517A213; Tue, 24 Oct 2017 17:35:16 +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 EFA376EF22; Tue, 24 Oct 2017 17:35:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9OHZC9v024596 for ; Tue, 24 Oct 2017 13:35:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E1635C552; Tue, 24 Oct 2017 17:35:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 94EA95C8A1; Tue, 24 Oct 2017 17:35:10 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 573D83C2C; Tue, 24 Oct 2017 17:35:09 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id t188so20186097pfd.10; Tue, 24 Oct 2017 10:35:09 -0700 (PDT) Received: from ps-f25-dev.eng.nutanix.com ([205.209.132.2]) by smtp.gmail.com with ESMTPSA id k2sm1333236pff.126.2017.10.24.10.35.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Oct 2017 10:35:08 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7AFC3C04B927 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7AFC3C04B927 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nA6U6PHR" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 573D83C2C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=saxenap.ltc@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 573D83C2C 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; bh=4Hr6U/0CYeM2CQZiVFSoQM4NCUNKBX42jbwt1a/wz3Y=; b=nA6U6PHRLqY43aqSGhZIGY0/X8SxeW1RAmhMwvcEeuOxTm9K2vCaVQ5wpuJWOrZJ9c XCLLO1xy5SdRVuM6QSwLTXbI03RskvHX6e2pjfvNpOGBTEHoT3ppBrSQ8xPZGAPMjsHG QlQbu8dAo95iu3MZQLBp1Wv00Zxx4YaSbqy9XVJIPcABYM2SqE/yMBrBTF/cJBXJnaT6 RkLdmXCtvB0RWBWooOSjUoJSQk5a4g25aROPYh5klQVHpJJbKbUeSPy7gykLyWCKYvqL eBW5H8kbUi1QkVdb3aHekVBvz6EFXlTZQpuQhcrsg4m0vrN9SAfLJGqiEXZ7u+dGRKv3 HhBg== 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; bh=4Hr6U/0CYeM2CQZiVFSoQM4NCUNKBX42jbwt1a/wz3Y=; b=dhnpMIfYDnnRHUimh8KjcynSV2nysVGpa1CTriMOYlanwDCMIEEd7xigVcF+AFFivI bk0diHT5X7piSV5cbPFM6fPFx3vFgBCU456Yq//xhZhSTprbEUH2/Oi475F/x8WDp/2K cCeMS8nQd4uh5Vv5CQ+6Xck+iLlvd2WW04m+rjtAAh4Nntt8mGz+mxeNruN0rezq2DTk Oncot6sBkhThNtFx1YlLnCbUCm3NvY9oypwDS//DDGoTcxQjf1pjpQHdXLmjTe5w0+XC hjf41cHgc/r+CoTx7DyDzG3z8fvR0NH73UnGuksACXSVVKQ/wEejECeAE+MMH1kR/tLB ereA== X-Gm-Message-State: AMCzsaUvj0fkIOJyfP1Wyn+FBDTjKCvqjUxC+nIQHqJ8GJSLDPh/VOiC JceoOGmdiq4Pjiige4wAwdTj0w== X-Google-Smtp-Source: ABhQp+SDN0WDm7x2OKUUC3D9UOMSw9DJV00RgunQJljs/w9RMuQOgIXxkrrbWRxtEugfUIF2BCORDQ== X-Received: by 10.101.64.198 with SMTP id u6mr15357250pgp.44.1508866508517; Tue, 24 Oct 2017 10:35:08 -0700 (PDT) From: Prerna Saxena To: libvir-list@redhat.com Date: Tue, 24 Oct 2017 10:34:54 -0700 Message-Id: <20171024173501.18105-2-saxenap.ltc@gmail.com> In-Reply-To: <20171024173501.18105-1-saxenap.ltc@gmail.com> References: <20171024173501.18105-1-saxenap.ltc@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 24 Oct 2017 17:35:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 24 Oct 2017 17:35:09 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'saxenap.ltc@gmail.com' RCPT:'' X-RedHat-Spam-Score: -2.41 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: --jdenemar@redhat.com, --pkrempa@redhat.com Subject: [libvirt] [[RFC] 1/8] Introduce virObjectTrylock() 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 24 Oct 2017 17:35:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a wrapper function that: (1) Attempts to take a lock on the object. (2) gracefully returns if the object is already locked. Signed-off-by: Prerna Saxena --- src/libvirt_private.syms | 1 + src/util/virobject.c | 26 ++++++++++++++++++++++++++ src/util/virobject.h | 4 ++++ src/util/virthread.c | 5 +++++ src/util/virthread.h | 1 + 5 files changed, 37 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9243c55..c0ab8b5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2362,6 +2362,7 @@ virObjectRWLockableNew; virObjectRWLockRead; virObjectRWLockWrite; virObjectRWUnlock; +virObjectTrylock; virObjectUnlock; virObjectUnref; =20 diff --git a/src/util/virobject.c b/src/util/virobject.c index cfa821c..796ea06 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -495,6 +495,32 @@ virObjectRWLockWrite(void *anyobj) =20 =20 /** + * virObjectTrylock: + * @anyobj: any instance of virObjectLockable or virObjectRWLockable + * + * Attempt to acquire a lock on @anyobj. The lock must be released by + * virObjectUnlock. + * Returns: + * 0: If the lock was successfully taken. + * errno : Indicates error. + * + * The caller is expected to have acquired a reference + * on the object before locking it (eg virObjectRef). + * The object must be unlocked before releasing this + * reference. + */ +int +virObjectTrylock(void *anyobj) +{ + virObjectLockablePtr obj =3D virObjectGetLockableObj(anyobj); + + if (!obj) + return -1; + + return virMutexTrylock(&obj->lock); +} + +/** * virObjectUnlock: * @anyobj: any instance of virObjectLockable * diff --git a/src/util/virobject.h b/src/util/virobject.h index ac6cf22..402ea32 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -124,6 +124,10 @@ void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); =20 +int +virObjectTrylock(void *lockableobj) + ATTRIBUTE_NONNULL(1); + void virObjectRWLockRead(void *lockableobj) ATTRIBUTE_NONNULL(1); diff --git a/src/util/virthread.c b/src/util/virthread.c index 6c49515..07b7a3f 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -89,6 +89,11 @@ void virMutexLock(virMutexPtr m) pthread_mutex_lock(&m->lock); } =20 +int virMutexTrylock(virMutexPtr m) +{ + return pthread_mutex_trylock(&m->lock); +} + void virMutexUnlock(virMutexPtr m) { pthread_mutex_unlock(&m->lock); diff --git a/src/util/virthread.h b/src/util/virthread.h index e466d9b..8e3da2c 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -132,6 +132,7 @@ int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETU= RN_CHECK; void virMutexDestroy(virMutexPtr m); =20 void virMutexLock(virMutexPtr m); +int virMutexTrylock(virMutexPtr m); void virMutexUnlock(virMutexPtr m); =20 =20 --=20 2.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list