From c8ab26e9f5aa398a208fcac3d8d11335f6c72632 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 10 Nov 2025 16:09:10 -0600 Subject: Touchup --- src/threadpool.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/threadpool.c') diff --git a/src/threadpool.c b/src/threadpool.c index 959c060..7a2f93a 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -182,14 +182,15 @@ taskqueue * taskqueue_new(void) { * @param tq A taskqueue to be freed. May be null */ void taskqueue_free(void *tq) { - if(!tq) return; + taskqueue *real = tq; + if(!real) return; - for(tqnode *p = ((taskqueue*)tq)->start, *n; p != NULL;) { + for(tqnode *p = real->start, *n; p != NULL;) { n = p->next; tqnode_free(p); p = n; } - free(tq); + free(real); return; } @@ -221,7 +222,8 @@ int taskqueue_push(taskqueue *tq, task *tsk) { int hf; if((hf = taskqueue_handlefirst(tq, tsk))) return (hf >= 0) ? 0 : -1; - tqnode *curstart = tq->start, *newstart = tqnode_new(tq->start, NULL, tsk); + tqnode *curstart = tq->start; + tqnode *newstart = tqnode_new(curstart, NULL, tsk); if(!newstart) return -1; curstart->prev = newstart; @@ -241,18 +243,18 @@ task * taskqueue_pop(taskqueue *tq) { if(!tq) ERRRET(EINVAL, NULL); if(tq->size <= 0) ERRRET(ENODATA, NULL); - tqnode *end = tq->end; - task *ret = end->task; + tqnode *curend = tq->end; + task *ret = curend->task; if(tq->size == 1) { tq->end = NULL; tq->start = NULL; } else { - tq->end = end->prev; + tq->end = curend->prev; tq->end->next = NULL; } - free(end); + free(curend); tq->size--; return ret; } @@ -270,7 +272,8 @@ int taskqueue_pushfront(taskqueue *tq, task *tsk) { int hf; if((hf = taskqueue_handlefirst(tq, tsk))) return (hf >= 0) ? 0 : -1; - tqnode *end =tq->end, *newend = tqnode_new(NULL, tq->end, tsk); + tqnode *end = tq->end; + tqnode *newend = tqnode_new(NULL, end, tsk); if(!newend) return -1; end->next = newend; @@ -290,18 +293,18 @@ task * taskqueue_popback(taskqueue *tq) { if(!tq) ERRRET(EINVAL, NULL); if(tq->size <= 0) ERRRET(ENODATA, NULL); - tqnode *start = tq->start; - task *ret = start->task; + tqnode *curstart = tq->start; + task *ret = curstart->task; if(tq->size == 1) { tq->start = NULL; tq->end = NULL; } else { - tq->start = start->next; + tq->start = curstart->next; tq->start->prev = NULL; } - free(start); + free(curstart); tq->size--; return ret; } @@ -321,7 +324,6 @@ int taskqueue_size(taskqueue *tq) { mtx_unlock(&(ctq)->mutex); \ return (retval); \ } \ - \ code \ mtx_unlock(&(ctq)->mutex); \ } while (0) @@ -413,8 +415,6 @@ void ctqueue_free(void *ctq) { free(real->thrdarr); free(real); - // TODO: figure out if it's necessary / a good idea to do error handling on these functions - return; } @@ -424,7 +424,7 @@ void ctqueue_free(void *ctq) { * * @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 + * @retval (int)[`thrd_error` | `thrd_nomem`, `thrd_success`] */ int ctqueue_waitpush(ctqueue *ctq, task *tsk) { if(!ctq || !tsk) ERRRET(EINVAL, -1); -- cgit v1.2.3