From 33647dd2c4f4af7c7cb7d99c1a6dac7f1d059a67 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 20 Oct 2025 15:51:49 -0500 Subject: Switch to unity build --- src/threadpool.h | 160 ------------------------------------------------------- 1 file changed, 160 deletions(-) delete mode 100644 src/threadpool.h (limited to 'src/threadpool.h') diff --git a/src/threadpool.h b/src/threadpool.h deleted file mode 100644 index 61dbacd..0000000 --- a/src/threadpool.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * @file threadpool.h - * @author syxhe (https://t.me/syxhe) - * @brief An implementation of a threadpool using libc threads - * @version 0.1 - * @date 2025-06-09 - * - * @copyright Copyright (c) 2025 - * - */ - -#ifndef __VXGG_REWRITE___THREADPOOL_H___193271180830131___ -#define __VXGG_REWRITE___THREADPOOL_H___193271180830131___ 1 - -#include "shared.h" -#include - -typedef struct task task; -typedef struct taskqueue taskqueue; -typedef struct ctqueue ctqueue; - -/** - * @brief Create a task - * - * @param callback Callback function the given data should be ran with. Must be non-null - * @param freecb Callback function for freeing the given data. May be null - * @param data Data to be passed to the callback. May be null - * @retval (task*)[NULL, task*] Returns a task object with set parameters. Returns `null` and sets errno on error - */ -task * task_init(gcallback callback, fcallback freecb, void *data); - -/** - * @brief Free a task - * - * @param tsk A task object to free. Frees data associated with task via `freecb` value specified in its creation. May be null - */ -void task_free(void *tsk); - -/** - * @brief Fire a task. Passes the `data` member to the specified `callback` - * - * @param tsk A task to be fired. Must be non-null - * @retval (int) Returns value of the fired callback. Returns -1 and sets errno on error - */ -int task_fire(task *tsk); - -/** - * @brief Fire and destroy a task simultaneously. Calls specified callback and free-callback on associated data - * - * @param tsk Task to be fired and destroyed. Must be non-null - * @retval (int) Returns value of the callback. Returns -1 and sets errno on error - */ -int task_fired(task *tsk); - - - -/** - * @brief Create a FIFO queue of tasks - * - * @retval (taskqueue*)[NULL, taskqueue*] Returns a new taskqueue object. Returns `null` and sets errno on error - */ -taskqueue * taskqueue_init(void); - -/** - * @brief Free a taskqueue - * - * @param tq A taskqueue to be freed. May be null - */ -void taskqueue_free(void *tq); - -/** - * @brief Push a task onto a taskqueue - * - * @param tq The taskqueue to be modified. Must be non-null - * @param tsk The task to push. Must be non-null - * @retval (int)[-1, 0] Returns 0 on success, sets errno and returns -1 on error - */ -int taskqueue_push(taskqueue *tq, task *tsk); - -/** - * @brief Pop a task from a taskqueue - * - * @param tq A taskqueue to grab a task from. Must be non-null - * @retval (task*)[NULL, task*] Returns a task on success, sets errno and returns `null` on error - */ -task * taskqueue_pop(taskqueue *tq); - -/** - * @brief Append a task to the front of a taskqueue - * - * @param tq The taskqueue to be modified. Must be non-null - * @param tsk The task to be appended. Must be non-null - * @retval (int)[-1, 0] Returns 0 on success, sets errno and returns -1 on error - */ -int taskqueue_pushfront(taskqueue *tq, task *tsk); - -/** - * @brief Pop a task from the back (most recently pushed task) of a taskqueue - * - * @param tq A taskqueue to pop from. Must be non-null - * @retval (task*)[NULL, task*] Returns a task on success, sets errno and returns `null` on error - */ -task * taskqueue_popback(taskqueue *tq); - - - -/** - * @brief Create a concurrent taskqueue with `size` allocated threads - * - * @param size Number of threads in the threadpool. Must be greater than zero - * @retval (ctqueue*)[NULL, ctqueue*] Returns a new ctqueue, sets errno and returns `null` on error - */ -ctqueue * ctqueue_init(int size); - -/** - * @brief Cancel all tasks being processed in a currently running concurrent taskqueue - * - * @param ctq The concurrent taskqueue to be canceled. Must be non-null - * @retval (int)[-1, 0] Returns 0 on success, sets errno and returns -1 on error - */ -int ctqueue_cancel(ctqueue *ctq); - -/** - * @brief Free a concurrent taskqueue - * @attention This cancels all currently running threads via `ctqueue_cancel` - * - * @param ctq The concurrent taskqueue to free. May be null - */ -void ctqueue_free(void *ctq); - -/** - * @brief Push a task onto a concurrent taskqueue - * @attention May block for an indefinite amount of time to push the task - * - * @param ctq The concurrent taskqueue to modify. Must be non-null - * @param tsk The task to push. Must be non-null - * @retval (int) Returns `thrd_success` on success, returns `thrd_error` or `thrd_nomem` on error - */ -int ctqueue_waitpush(ctqueue *ctq, task *tsk); - - -/** - * @brief Pop a task from the concurrent taskqueue - * @attention May block for an indefinite amount of time to pop the task - * - * @param ctq The concurrent taskqueue to pop from. Must be non-null - * @retval (task*)[NULL, task*] Returns a task on success, sets errno and returns `null` on error - */ -task * ctqueue_waitpop(ctqueue *ctq); - -/** - * @brief Start the threads allocated to a concurrent taskqueue - * @attention Threads will not consume pushed tasks until this function is ran - * - * @param ctq A concurrent taskqueue to start. Must be non-null - * @retval (int)[-1, 0] Returns 0 on success, sets errno and returns -1 on error - */ -int ctqueue_start(ctqueue *ctq); - -#endif \ No newline at end of file -- cgit v1.2.3