diff --git a/iiod/thread-pool.c b/iiod/thread-pool.c index d8fa6b833..2fd30825f 100644 --- a/iiod/thread-pool.c +++ b/iiod/thread-pool.c @@ -31,6 +31,7 @@ struct thread_pool { pthread_cond_t thread_count_cond; unsigned int thread_count; int stop_fd; + bool stop; }; struct thread_body_data { @@ -130,6 +131,8 @@ struct thread_pool * thread_pool_new(void) return NULL; } + pool->stop = false; + pthread_mutex_init(&pool->thread_count_lock, NULL); pthread_cond_init(&pool->thread_count_cond, NULL); pool->thread_count = 0; @@ -147,6 +150,8 @@ void thread_pool_stop(struct thread_pool *pool) uint64_t e = 1; int ret; + pool->stop = true; + do { ret = write(pool->stop_fd, &e, sizeof(e)); } while (ret == -1 && errno == EINTR); @@ -170,6 +175,11 @@ void thread_pool_stop_and_wait(struct thread_pool *pool) } while (ret != -1 || errno == EINTR); } +bool thread_pool_is_stopped(const struct thread_pool *pool) +{ + return pool->stop; +} + 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 3b83d5693..b4e8bf0bb 100644 --- a/iiod/thread-pool.h +++ b/iiod/thread-pool.h @@ -9,6 +9,8 @@ #ifndef __THREAD_POOL_H__ #define __THREAD_POOL_H__ +#include + struct thread_pool; struct thread_pool * thread_pool_new(void); @@ -16,6 +18,7 @@ struct thread_pool * thread_pool_new(void); 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_destroy(struct thread_pool *pool);