From f5f8422559a08ba44a409a4f97fc11bdfb3e2b2a Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Tue, 4 Apr 2023 11:00:22 +0200 Subject: [PATCH] iiod: thread_pool: Add function thread_pool_restart() This function can be used to re-activate a thread pool that has been previously stopped with thread_pool_stop(). Signed-off-by: Paul Cercueil --- iiod/thread-pool.c | 8 ++++++++ iiod/thread-pool.h | 1 + 2 files changed, 9 insertions(+) diff --git a/iiod/thread-pool.c b/iiod/thread-pool.c index 65b680ee5..3b00a54ef 100644 --- a/iiod/thread-pool.c +++ b/iiod/thread-pool.c @@ -185,6 +185,14 @@ bool thread_pool_is_stopped(const struct thread_pool *pool) return pool->stop; } +void thread_pool_restart(struct thread_pool *pool) +{ + if (pool->stop) { + thread_pool_purge_events(pool); + pool->stop = false; + } +} + void thread_pool_destroy(struct thread_pool *pool) { pthread_mutex_destroy(&pool->thread_count_lock); diff --git a/iiod/thread-pool.h b/iiod/thread-pool.h index b4e8bf0bb..42d428598 100644 --- a/iiod/thread-pool.h +++ b/iiod/thread-pool.h @@ -19,6 +19,7 @@ int thread_pool_get_poll_fd(const struct thread_pool *pool); void thread_pool_stop(struct thread_pool *pool); void thread_pool_stop_and_wait(struct thread_pool *pool); bool thread_pool_is_stopped(const struct thread_pool *pool); +void thread_pool_restart(struct thread_pool *pool); void thread_pool_destroy(struct thread_pool *pool);