diff options
Diffstat (limited to 'src/std')
-rw-r--r-- | src/std/buffer.c | 3 | ||||
-rw-r--r-- | src/std/thread_pool.c | 10 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c index 4ec9c29..fbfb9da 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -70,8 +70,7 @@ int buffer_expand(Buffer *self, usize size) { } void* buffer_get(Buffer *self, usize index, usize type_size) { - usize real_index; - real_index = index * type_size; + usize real_index = index * type_size; assert(real_index < self->size); return &self->data[real_index]; } 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; } |