From nobody Mon Feb 9 14:02:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1595499379; cv=none; d=zohomail.com; s=zohoarc; b=gGjxzZchj9JznciSRfP+eQPkQXOXrRL9aDFWLFPKdxeGwMlsf5aGf1kPrqBQ67aBVjnTb2qW8OEp13NmnFp93eK3wol64CJGsrHMEjK58dSsBV1yREybFaACTpPuiMxAAlBmnH6h6cKBx/jTSngRiFz/ThW63Qj7NjyOWMmO6ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595499379; h=Content-Type:Content-Transfer-Encoding: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=zNCrffuNc57BZFnQaS07OHQlnZ6eOLapZjoqllYsyJc=; b=nOjCuvGawAwDlCVy/DMSELo0sk8gVUAUL5sUn0uTZCUgeFBsR0LvBYXLbijkgjLriKIDrMCNQHtNkw66dyLP5DY5YhNFnVUJ0/kEhNU6kKvFrn3/ERcpXc0ScARZo3Viuq9HffBh0IGdLNFVLx0kOy8BTrakgV+yDhZ0ICBLCIE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1595499379350919.171984580293; Thu, 23 Jul 2020 03:16:19 -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-478-CloLdCsMOlmpE_jM4pVu2A-1; Thu, 23 Jul 2020 06:16:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8718CE924; Thu, 23 Jul 2020 10:16:10 +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 66CA25D9D3; Thu, 23 Jul 2020 10:16:10 +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 2F4D09625C; Thu, 23 Jul 2020 10:16:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06NAFrRO008461 for ; Thu, 23 Jul 2020 06:15:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 32CCB2156A49; Thu, 23 Jul 2020 10:15:53 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DE732156A2D for ; Thu, 23 Jul 2020 10:15:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FF071832D2C for ; Thu, 23 Jul 2020 10:15:50 +0000 (UTC) Received: from relay3.sw.ru (relay.sw.ru [185.231.240.75]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-NmwqiNwnMt-z6mb8oJVUEA-1; Thu, 23 Jul 2020 06:15:47 -0400 Received: from [172.16.50.220] (helo=vz7.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jyYGM-0007ZV-R2 for libvir-list@redhat.com; Thu, 23 Jul 2020 13:15:42 +0300 X-MC-Unique: CloLdCsMOlmpE_jM4pVu2A-1 X-MC-Unique: NmwqiNwnMt-z6mb8oJVUEA-1 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Subject: [PATCH v2 03/13] util: add stop/drain functions to thread pool Date: Thu, 23 Jul 2020 13:14:03 +0300 Message-Id: <1595499253-584162-4-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1595499253-584162-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1595499253-584162-1-git-send-email-nshirokovskiy@virtuozzo.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com 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.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Stop just send signal for threads to exit when they finish with current task. Drain waits when all threads will finish. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 2 ++ src/util/virthreadpool.c | 43 ++++++++++++++++++++++++++++++++++++++----- src/util/virthreadpool.h | 3 +++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cf3ccab..0a9afc5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3328,6 +3328,7 @@ virThreadJobSetWorker; =20 =20 # util/virthreadpool.h +virThreadPoolDrain; virThreadPoolFree; virThreadPoolGetCurrentWorkers; virThreadPoolGetFreeWorkers; @@ -3338,6 +3339,7 @@ virThreadPoolGetPriorityWorkers; virThreadPoolNewFull; virThreadPoolSendJob; virThreadPoolSetParameters; +virThreadPoolStop; =20 =20 # util/virtime.h diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 10a44de..ca44f55 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -268,19 +268,27 @@ virThreadPoolNewFull(size_t minWorkers, =20 } =20 -void virThreadPoolFree(virThreadPoolPtr pool) -{ - virThreadPoolJobPtr job; =20 - if (!pool) +static void +virThreadPoolStopLocked(virThreadPoolPtr pool) +{ + if (pool->quit) return; =20 - virMutexLock(&pool->mutex); pool->quit =3D true; if (pool->nWorkers > 0) virCondBroadcast(&pool->cond); if (pool->nPrioWorkers > 0) virCondBroadcast(&pool->prioCond); +} + + +static void +virThreadPoolDrainLocked(virThreadPoolPtr pool) +{ + virThreadPoolJobPtr job; + + virThreadPoolStopLocked(pool); =20 while (pool->nWorkers > 0 || pool->nPrioWorkers > 0) ignore_value(virCondWait(&pool->quit_cond, &pool->mutex)); @@ -289,6 +297,15 @@ void virThreadPoolFree(virThreadPoolPtr pool) pool->jobList.head =3D pool->jobList.head->next; VIR_FREE(job); } +} + +void virThreadPoolFree(virThreadPoolPtr pool) +{ + if (!pool) + return; + + virMutexLock(&pool->mutex); + virThreadPoolDrainLocked(pool); =20 VIR_FREE(pool->workers); virMutexUnlock(&pool->mutex); @@ -475,3 +492,19 @@ virThreadPoolSetParameters(virThreadPoolPtr pool, virMutexUnlock(&pool->mutex); return -1; } + +void +virThreadPoolStop(virThreadPoolPtr pool) +{ + virMutexLock(&pool->mutex); + virThreadPoolStopLocked(pool); + virMutexUnlock(&pool->mutex); +} + +void +virThreadPoolDrain(virThreadPoolPtr pool) +{ + virMutexLock(&pool->mutex); + virThreadPoolDrainLocked(pool); + virMutexUnlock(&pool->mutex); +} diff --git a/src/util/virthreadpool.h b/src/util/virthreadpool.h index c97d9b3..dd1aaf3 100644 --- a/src/util/virthreadpool.h +++ b/src/util/virthreadpool.h @@ -56,3 +56,6 @@ int virThreadPoolSetParameters(virThreadPoolPtr pool, long long int minWorkers, long long int maxWorkers, long long int prioWorkers); + +void virThreadPoolStop(virThreadPoolPtr pool); +void virThreadPoolDrain(virThreadPoolPtr pool); --=20 1.8.3.1