mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
pthreadpool: add pthreadpool_max_threads() and pthreadpool_queued_jobs() helpers
These can be used to implement some kind of flow control in the caller. E.g. unless pthreadpool_queued_jobs() is lower than pthreadpool_max_threads() is good to prepare new jobs. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
76474a6fad
commit
505d298e81
@ -196,6 +196,29 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t pthreadpool_max_threads(struct pthreadpool *pool)
|
||||
{
|
||||
return pool->max_threads;
|
||||
}
|
||||
|
||||
size_t pthreadpool_queued_jobs(struct pthreadpool *pool)
|
||||
{
|
||||
int res;
|
||||
int unlock_res;
|
||||
size_t ret;
|
||||
|
||||
res = pthread_mutex_lock(&pool->mutex);
|
||||
if (res != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = pool->num_jobs;
|
||||
|
||||
unlock_res = pthread_mutex_unlock(&pool->mutex);
|
||||
assert(unlock_res == 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void pthreadpool_prepare_pool(struct pthreadpool *pool)
|
||||
{
|
||||
int ret;
|
||||
|
@ -50,6 +50,27 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
void *private_data),
|
||||
void *signal_fn_private_data);
|
||||
|
||||
/**
|
||||
* @brief Get the max threads value of pthreadpool
|
||||
*
|
||||
* @note This can be 0 for strict sync processing.
|
||||
*
|
||||
* @param[in] pool The pool
|
||||
* @return number of possible threads
|
||||
*/
|
||||
size_t pthreadpool_max_threads(struct pthreadpool *pool);
|
||||
|
||||
/**
|
||||
* @brief The number of queued jobs of pthreadpool
|
||||
*
|
||||
* This is the number of jobs added by pthreadpool_add_job(),
|
||||
* which are not yet processed by a thread.
|
||||
*
|
||||
* @param[in] pool The pool
|
||||
* @return The number of jobs
|
||||
*/
|
||||
size_t pthreadpool_queued_jobs(struct pthreadpool *pool);
|
||||
|
||||
/**
|
||||
* @brief Destroy a pthreadpool
|
||||
*
|
||||
|
@ -52,6 +52,16 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t pthreadpool_max_threads(struct pthreadpool *pool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t pthreadpool_queued_jobs(struct pthreadpool *pool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
|
||||
void (*fn)(void *private_data), void *private_data)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user