2010-12-08 06:19:06 +00:00
|
|
|
/*
|
2012-12-13 15:39:07 +00:00
|
|
|
* virthreadpool.h: a generic thread pool implementation
|
2010-12-08 06:19:06 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Hu Tao
|
|
|
|
* Copyright (C) 2010 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-08 06:19:06 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:44 +00:00
|
|
|
#pragma once
|
2010-12-08 06:19:06 +00:00
|
|
|
|
2019-06-18 16:12:44 +00:00
|
|
|
#include "internal.h"
|
2010-12-08 06:19:06 +00:00
|
|
|
|
|
|
|
typedef struct _virThreadPool virThreadPool;
|
|
|
|
|
|
|
|
typedef void (*virThreadPoolJobFunc)(void *jobdata, void *opaque);
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virThreadPool *virThreadPoolNewFull(size_t minWorkers,
|
2015-03-20 16:44:25 +00:00
|
|
|
size_t maxWorkers,
|
|
|
|
size_t prioWorkers,
|
|
|
|
virThreadPoolJobFunc func,
|
2020-02-14 11:20:10 +00:00
|
|
|
const char *name,
|
2015-03-20 16:44:25 +00:00
|
|
|
void *opaque) ATTRIBUTE_NONNULL(4);
|
2010-12-08 06:19:06 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
size_t virThreadPoolGetMinWorkers(virThreadPool *pool);
|
|
|
|
size_t virThreadPoolGetMaxWorkers(virThreadPool *pool);
|
|
|
|
size_t virThreadPoolGetPriorityWorkers(virThreadPool *pool);
|
|
|
|
size_t virThreadPoolGetCurrentWorkers(virThreadPool *pool);
|
|
|
|
size_t virThreadPoolGetFreeWorkers(virThreadPool *pool);
|
|
|
|
size_t virThreadPoolGetJobQueueDepth(virThreadPool *pool);
|
2012-08-09 10:48:17 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virThreadPoolFree(virThreadPool *pool);
|
2010-12-08 06:19:06 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virThreadPoolSendJob(virThreadPool *pool,
|
2011-08-12 12:04:31 +00:00
|
|
|
unsigned int priority,
|
2010-12-08 06:19:06 +00:00
|
|
|
void *jobdata) ATTRIBUTE_NONNULL(1)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2010-12-08 06:19:06 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virThreadPoolSetParameters(virThreadPool *pool,
|
admin: Introduce virAdmServerSetThreadPoolParameters
Since threadpool increments the current number of threads according to current
load, i.e. how many jobs are waiting in the queue. The count however, is
constrained by max and min limits of workers. The logic of this new API works
like this:
1) setting the minimum
a) When the limit is increased, depending on the current number of
threads, new threads are possibly spawned if the current number of
threads is less than the new minimum limit
b) Decreasing the minimum limit has no possible effect on the current
number of threads
2) setting the maximum
a) Icreasing the maximum limit has no immediate effect on the current
number of threads, it only allows the threadpool to spawn more
threads when new jobs, that would otherwise end up queued, arrive.
b) Decreasing the maximum limit may affect the current number of
threads, if the current number of threads is less than the new
maximum limit. Since there may be some ongoing time-consuming jobs
that would effectively block this API from killing any threads.
Therefore, this API is asynchronous with best-effort execution,
i.e. the necessary number of workers will be terminated once they
finish their previous job, unless other workers had already
terminated, decreasing the limit to the requested value.
3) setting priority workers
- both increase and decrease in count of these workers have an
immediate impact on the current number of workers, new ones will be
spawned or some of them get terminated respectively.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-02-22 13:24:04 +00:00
|
|
|
long long int minWorkers,
|
|
|
|
long long int maxWorkers,
|
|
|
|
long long int prioWorkers);
|
2020-07-09 07:58:02 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virThreadPoolStop(virThreadPool *pool);
|
|
|
|
void virThreadPoolDrain(virThreadPool *pool);
|