From nobody Mon Feb 9 14:38:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1644359566; cv=none; d=zohomail.com; s=zohoarc; b=U8LRULNpiQmZweB0OBVKuufn859Zgv8JETbKx6pOuR6W8t7iGSEo15orByhQLvBFSXfdkrRnAyj8E4DxEP5436h1CNqYAcAUXX40z8RM68JXkni+/nVSdZqodKvyJPJu3uy/SgPcwno128mBCyDo63Ti4ENngs99C0cK5Q9iHyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644359566; 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=iex4krl+AoaT64QcFTp9wEMOeDmUtH4keLKzogfXUVs=; b=jXzMf3MuIcg++8pjFtIoRG/CbE8++ZUzasUaWCeDfORhtVb1Nhu1yLWZOZvbdZ/fOzLbNXong5DbmXLOB4/5dB9ReV/iH6gJ6VFDq2QkIwYvBiXno315+QPwszzBfklofNBYJTgVQI+cFa+B8YJoxEmcUCuMI5KxaUu30Q11LM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1644359566499252.69378323151705; Tue, 8 Feb 2022 14:32:46 -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-347-q1BRkh8HOSG9FeQccj9i6w-1; Tue, 08 Feb 2022 17:32:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 033C31091DA2; Tue, 8 Feb 2022 22:32:37 +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 81CBB4CEF8; Tue, 8 Feb 2022 22:32:35 +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 7D0024CA93; Tue, 8 Feb 2022 22:32:32 +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 217DCH1U006285 for ; Mon, 7 Feb 2022 08:12:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4A5851038ACB; Mon, 7 Feb 2022 13:12:17 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.192.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93E991038AC9; Mon, 7 Feb 2022 13:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644359565; 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=iex4krl+AoaT64QcFTp9wEMOeDmUtH4keLKzogfXUVs=; b=b/OJeOcM08w8atDL6LE5DS5I5J06fCgvkJCHcQDYZhUET2lU/2E160vZsooxYq3bMv+z5N 5ooHwmseChhkj/gbkBgoQq8H78S6VjU7KEMXl+1W+FH2w9VqrrOobdlzTw2/e5smxEhRbY AeYSCYfjq4W621KngB0e1vDa0zelrgY= X-MC-Unique: q1BRkh8HOSG9FeQccj9i6w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 01/11] virthreadpool: Use automatic memory management Date: Mon, 7 Feb 2022 14:12:04 +0100 Message-Id: <20220207131214.54855-2-twiederh@redhat.com> In-Reply-To: <20220207131214.54855-1-twiederh@redhat.com> References: <20220207131214.54855-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.15 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: 1644359567140100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- src/util/virthreadpool.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 426840e435..b6d154802a 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -306,15 +306,13 @@ void virThreadPoolFree(virThreadPool *pool) if (!pool) return; =20 - virMutexLock(&pool->mutex); - virThreadPoolDrainLocked(pool); + virThreadPoolDrain(pool); =20 if (pool->identity) g_object_unref(pool->identity); =20 g_free(pool->jobName); g_free(pool->workers); - virMutexUnlock(&pool->mutex); virMutexDestroy(&pool->mutex); virCondDestroy(&pool->quit_cond); virCondDestroy(&pool->cond); @@ -326,66 +324,60 @@ void virThreadPoolFree(virThreadPool *pool) =20 size_t virThreadPoolGetMinWorkers(virThreadPool *pool) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t ret; =20 - virMutexLock(&pool->mutex); ret =3D pool->minWorkers; - virMutexUnlock(&pool->mutex); =20 return ret; } =20 size_t virThreadPoolGetMaxWorkers(virThreadPool *pool) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t ret; =20 - virMutexLock(&pool->mutex); ret =3D pool->maxWorkers; - virMutexUnlock(&pool->mutex); =20 return ret; } =20 size_t virThreadPoolGetPriorityWorkers(virThreadPool *pool) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t ret; =20 - virMutexLock(&pool->mutex); ret =3D pool->nPrioWorkers; - virMutexUnlock(&pool->mutex); =20 return ret; } =20 size_t virThreadPoolGetCurrentWorkers(virThreadPool *pool) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t ret; =20 - virMutexLock(&pool->mutex); ret =3D pool->nWorkers; - virMutexUnlock(&pool->mutex); =20 return ret; } =20 size_t virThreadPoolGetFreeWorkers(virThreadPool *pool) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t ret; =20 - virMutexLock(&pool->mutex); ret =3D pool->freeWorkers; - virMutexUnlock(&pool->mutex); =20 return ret; } =20 size_t virThreadPoolGetJobQueueDepth(virThreadPool *pool) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t ret; =20 - virMutexLock(&pool->mutex); ret =3D pool->jobQueueDepth; - virMutexUnlock(&pool->mutex); =20 return ret; } @@ -398,9 +390,9 @@ int virThreadPoolSendJob(virThreadPool *pool, unsigned int priority, void *jobData) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); virThreadPoolJob *job; =20 - virMutexLock(&pool->mutex); if (pool->quit) goto error; =20 @@ -431,11 +423,9 @@ int virThreadPoolSendJob(virThreadPool *pool, if (priority) virCondSignal(&pool->prioCond); =20 - virMutexUnlock(&pool->mutex); return 0; =20 error: - virMutexUnlock(&pool->mutex); return -1; } =20 @@ -445,11 +435,10 @@ virThreadPoolSetParameters(virThreadPool *pool, long long int maxWorkers, long long int prioWorkers) { + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); size_t max; size_t min; =20 - virMutexLock(&pool->mutex); - max =3D maxWorkers >=3D 0 ? maxWorkers : pool->maxWorkers; min =3D minWorkers >=3D 0 ? minWorkers : pool->minWorkers; if (min > max) { @@ -490,26 +479,24 @@ virThreadPoolSetParameters(virThreadPool *pool, pool->maxPrioWorkers =3D prioWorkers; } =20 - virMutexUnlock(&pool->mutex); return 0; =20 error: - virMutexUnlock(&pool->mutex); return -1; } =20 void virThreadPoolStop(virThreadPool *pool) { - virMutexLock(&pool->mutex); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); + virThreadPoolStopLocked(pool); - virMutexUnlock(&pool->mutex); } =20 void virThreadPoolDrain(virThreadPool *pool) { - virMutexLock(&pool->mutex); + VIR_LOCK_GUARD lock =3D virLockGuardLock(&pool->mutex); + virThreadPoolDrainLocked(pool); - virMutexUnlock(&pool->mutex); } --=20 2.31.1