diff options
Diffstat (limited to 'src/logos')
-rw-r--r-- | src/logos/threadpool.c | 20 | ||||
-rw-r--r-- | src/logos/threadpool.h | 34 |
2 files changed, 27 insertions, 27 deletions
diff --git a/src/logos/threadpool.c b/src/logos/threadpool.c index bf54d08..0e82d98 100644 --- a/src/logos/threadpool.c +++ b/src/logos/threadpool.c @@ -6,8 +6,8 @@ #include "log.h" #include "ring_queue.h" -static void *worker_factory(void *arg) { - threadpool_worker *worker = arg; +static void* worker_factory(void* arg) { + threadpool_worker* worker = arg; // INFO("Starting job thread %d", worker->id); // Run forever, waiting for jobs. @@ -50,7 +50,7 @@ static void *worker_factory(void *arg) { return NULL; } -bool threadpool_create(threadpool *pool, u8 thread_count, u32 queue_size) { +bool threadpool_create(threadpool* pool, u8 thread_count, u32 queue_size) { INFO("Threadpool init"); pool->next_task_id = 0; pool->context = NULL; @@ -84,13 +84,13 @@ bool threadpool_create(threadpool *pool, u8 thread_count, u32 queue_size) { return true; } -bool threadpool_add_task(threadpool *pool, tpool_task_start do_task, +bool threadpool_add_task(threadpool* pool, tpool_task_start do_task, tpool_task_on_complete on_success, tpool_task_on_complete on_fail, - bool buffer_result_for_main_thread, void *param_data, u32 param_data_size, + bool buffer_result_for_main_thread, void* param_data, u32 param_data_size, u32 result_data_size) { - void *result_data = malloc(result_data_size); + void* result_data = malloc(result_data_size); - task *work_task = malloc(sizeof(task)); + task* work_task = malloc(sizeof(task)); work_task->task_id = 0; work_task->do_task = do_task; work_task->on_success = on_success; @@ -123,11 +123,11 @@ bool threadpool_add_task(threadpool *pool, tpool_task_start do_task, return true; } -void threadpool_process_results(threadpool *pool, int _num_to_process) { +void threadpool_process_results(threadpool* pool, int _num_to_process) { pthread_mutex_lock(&pool->mutex); size_t num_results = deferred_task_result_darray_len(pool->results); if (num_results > 0) { - u32 _size = ((deferred_task_result *)pool->results->data)[num_results].result_data_size; + u32 _size = ((deferred_task_result*)pool->results->data)[num_results].result_data_size; deferred_task_result res; deferred_task_result_darray_pop(pool->results, &res); pthread_mutex_unlock(&pool->mutex); @@ -138,4 +138,4 @@ void threadpool_process_results(threadpool *pool, int _num_to_process) { } } -void threadpool_set_ctx(threadpool *pool, void *ctx) { pool->context = ctx; }
\ No newline at end of file +void threadpool_set_ctx(threadpool* pool, void* ctx) { pool->context = ctx; }
\ No newline at end of file diff --git a/src/logos/threadpool.h b/src/logos/threadpool.h index 2cd70fd..6390a38 100644 --- a/src/logos/threadpool.h +++ b/src/logos/threadpool.h @@ -15,20 +15,20 @@ struct threadpool; typedef struct threadpool threadpool; typedef struct task_globals { - threadpool *pool; - void *ctx; + threadpool* pool; + void* ctx; } task_globals; /* function pointer */ -typedef bool (*tpool_task_start)(void *, void *); +typedef bool (*tpool_task_start)(void*, void*); /* function pointer */ -typedef void (*tpool_task_on_complete)(task_globals *, void *); +typedef void (*tpool_task_on_complete)(task_globals*, void*); typedef struct threadpool_worker { u16 id; pthread_t thread; - threadpool *pool; // pointer back to the pool so we can get the mutex and cond + threadpool* pool; // pointer back to the pool so we can get the mutex and cond } threadpool_worker; typedef enum tpool_task_status { @@ -42,9 +42,9 @@ typedef struct tpool_task { tpool_task_on_complete on_failure; bool buffer_result_for_main_thread; /** @brief a pointer to the parameters data that will be passed into the task. */ - void *params; + void* params; u32 param_size; - void *result_data; + void* result_data; u32 result_data_size; } task; @@ -53,7 +53,7 @@ typedef struct deferred_task_result { tpool_task_on_complete callback; u32 result_data_size; // this gets passed to the void* argument of `tpool_task_on_complete` - void *result_data; + void* result_data; } deferred_task_result; #ifndef TYPED_TASK_RESULT_ARRAY @@ -62,14 +62,14 @@ KITC_DECL_TYPED_ARRAY(deferred_task_result) // creates "deferred_task_result_da #endif struct threadpool { - ring_queue *task_queue; + ring_queue* task_queue; pthread_mutex_t mutex; pthread_cond_t has_tasks; threadpool_worker workers[MAX_NUM_THREADS]; - deferred_task_result_darray *results; + deferred_task_result_darray* results; u64 next_task_id; - void *context; + void* context; }; /** @@ -77,20 +77,20 @@ struct threadpool { * @param thread_count how many threads to spawn * @param queue_size max size of task queue */ -bool threadpool_create(threadpool *pool, u8 thread_count, u32 queue_size); -void threadpool_destroy(threadpool *pool); +bool threadpool_create(threadpool* pool, u8 thread_count, u32 queue_size); +void threadpool_destroy(threadpool* pool); /** @brief set a context variable for the threadpool that task data has access to */ -void threadpool_set_ctx(threadpool *pool, void *ctx); +void threadpool_set_ctx(threadpool* pool, void* ctx); /** * @brief Add a task to the threadpool */ -bool threadpool_add_task(threadpool *pool, tpool_task_start do_task, +bool threadpool_add_task(threadpool* pool, tpool_task_start do_task, tpool_task_on_complete on_success, tpool_task_on_complete on_fail, - bool buffer_result_for_main_thread, void *param_data, u32 param_data_size, + bool buffer_result_for_main_thread, void* param_data, u32 param_data_size, u32 result_data_size); -void threadpool_process_results(threadpool *pool, int num_to_process); +void threadpool_process_results(threadpool* pool, int num_to_process); u32 Tpool_GetNumWorkers(); // how many threads are we using
\ No newline at end of file |