Skip to content

Commit

Permalink
iiod: thread_pool: Add helper thread_pool_purge_events()
Browse files Browse the repository at this point in the history
Factorize the code that purges all the data left in the event file
descriptor into a function named thread_pool_purge_events().

This function is only called once for now, but it will be used again in
a future commit.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jun 5, 2023
1 parent 43f03ac commit e26bff1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions iiod/thread-pool.c
Expand Up @@ -157,11 +157,18 @@ void thread_pool_stop(struct thread_pool *pool)
} while (ret == -1 && errno == EINTR);
}

void thread_pool_stop_and_wait(struct thread_pool *pool)
static void thread_pool_purge_events(struct thread_pool *pool)
{
uint64_t e;
int ret;

do {
ret = read(pool->stop_fd, &e, sizeof(e));
} while (ret != -1 || errno == EINTR);
}

void thread_pool_stop_and_wait(struct thread_pool *pool)
{
thread_pool_stop(pool);

pthread_mutex_lock(&pool->thread_count_lock);
Expand All @@ -170,9 +177,7 @@ void thread_pool_stop_and_wait(struct thread_pool *pool)
&pool->thread_count_lock);
pthread_mutex_unlock(&pool->thread_count_lock);

do {
ret = read(pool->stop_fd, &e, sizeof(e));
} while (ret != -1 || errno == EINTR);
thread_pool_purge_events(pool);
}

bool thread_pool_is_stopped(const struct thread_pool *pool)
Expand Down

0 comments on commit e26bff1

Please sign in to comment.