Skip to content

Commit e26bff1

Browse files
committed
iiod: thread_pool: Add helper thread_pool_purge_events()
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 <[email protected]>
1 parent 43f03ac commit e26bff1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

iiod/thread-pool.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,18 @@ void thread_pool_stop(struct thread_pool *pool)
157157
} while (ret == -1 && errno == EINTR);
158158
}
159159

160-
void thread_pool_stop_and_wait(struct thread_pool *pool)
160+
static void thread_pool_purge_events(struct thread_pool *pool)
161161
{
162162
uint64_t e;
163163
int ret;
164164

165+
do {
166+
ret = read(pool->stop_fd, &e, sizeof(e));
167+
} while (ret != -1 || errno == EINTR);
168+
}
169+
170+
void thread_pool_stop_and_wait(struct thread_pool *pool)
171+
{
165172
thread_pool_stop(pool);
166173

167174
pthread_mutex_lock(&pool->thread_count_lock);
@@ -170,9 +177,7 @@ void thread_pool_stop_and_wait(struct thread_pool *pool)
170177
&pool->thread_count_lock);
171178
pthread_mutex_unlock(&pool->thread_count_lock);
172179

173-
do {
174-
ret = read(pool->stop_fd, &e, sizeof(e));
175-
} while (ret != -1 || errno == EINTR);
180+
thread_pool_purge_events(pool);
176181
}
177182

178183
bool thread_pool_is_stopped(const struct thread_pool *pool)

0 commit comments

Comments
 (0)