aboutsummaryrefslogtreecommitdiff
path: root/src/std/thread_pool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/std/thread_pool.c')
-rw-r--r--src/std/thread_pool.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/std/thread_pool.c b/src/std/thread_pool.c
index 8f6e180..1e2addf 100644
--- a/src/std/thread_pool.c
+++ b/src/std/thread_pool.c
@@ -7,8 +7,10 @@
static CHECK_RESULT int thread_pool_take_task(amal_thread_pool *self, amal_thread_pool_task **result) {
*result = NULL;
cleanup_if_error(amal_mutex_lock(&self->task_select_mutex, "thread_pool_take_task"));
- if(self->num_finished_queued_tasks < (int)buffer_get_size(&self->queued_tasks, amal_thread_pool_task) && !self->dead)
- *result = buffer_get(&self->queued_tasks, self->num_finished_queued_tasks, sizeof(amal_thread_pool_task));
+ if((self->num_taken_tasks < (int)buffer_get_size(&self->queued_tasks, amal_thread_pool_task)) && !self->dead) {
+ *result = buffer_get(&self->queued_tasks, self->num_taken_tasks, sizeof(amal_thread_pool_task));
+ self->num_taken_tasks++;
+ }
cleanup:
amal_mutex_tryunlock(&self->task_select_mutex);
return 0;
@@ -80,7 +82,7 @@ int thread_pool_init(amal_thread_pool *self, int num_threads) {
}
self->dead = bool_false;
- self->num_finished_queued_tasks = 0;
+ self->num_taken_tasks = 0;
self->threads = NULL;
ignore_result_int(buffer_init(&self->queued_tasks, NULL));
@@ -174,7 +176,7 @@ bool thread_pool_join_all_tasks(amal_thread_pool *self) {
died = self->dead;
self->dead = bool_false;
buffer_clear(&self->queued_tasks);
- self->num_finished_queued_tasks = 0;
+ self->num_taken_tasks = 0;
return !died;
}