From 458e7b176c6706f14c1f61c13b41a9a1dc61f0e3 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 27 Mar 2024 12:52:49 -0700 Subject: [PATCH] rm job system error handling; Having it in the job system is too gross. Use lovrTry instead. --- src/core/job.c | 44 ++++++-------------------------------------- src/core/job.h | 6 +----- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/src/core/job.c b/src/core/job.c index 9e9df6a6..1d3f3dd3 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1,9 +1,6 @@ #include "job.h" #include #include -#include -#include -#include #include #define MAX_WORKERS 64 @@ -11,9 +8,9 @@ struct job { job* next; - atomic_uint done; - union { fn_job* fn; char* error; }; + fn_job* fn; void* arg; + atomic_uint done; }; static struct { @@ -28,8 +25,6 @@ static struct { bool quit; } state; -static thread_local jmp_buf catch; - // Must hold lock, this will unlock it, state.head must exist static void runJob(void) { job* job = state.head; @@ -37,12 +32,7 @@ static void runJob(void) { if (!job->next) state.tail = NULL; mtx_unlock(&state.lock); - if (setjmp(catch) == 0) { - fn_job* fn = job->fn; - job->error = NULL; - fn(job, job->arg); - } - + job->fn(job->arg); job->done = true; } @@ -98,10 +88,9 @@ void job_destroy(void) { job* job_start(fn_job* fn, void* arg) { mtx_lock(&state.lock); - // If there's no free job available, return NULL as a backpressure signal - // Caller can choose how to handle: error, wait on older jobs, just run the job, etc. if (!state.pool) { mtx_unlock(&state.lock); + fn(arg); return NULL; } @@ -126,23 +115,9 @@ job* job_start(fn_job* fn, void* arg) { return job; } -void job_abort(job* job, const char* error) { - size_t length = strlen(error); - job->error = malloc(length + 1); - if (job->error) memcpy(job->error, error, length + 1); - else job->error = strdup("Out of memory"); - longjmp(catch, 22); -} - -void job_vabort(job* job, const char* format, va_list args) { - int length = vsnprintf(NULL, 0, format, args); - job->error = malloc(length + 1); - if (job->error) vsnprintf(job->error, length + 1, format, args); - else job->error = strdup("Out of memory"); - longjmp(catch, 22); -} - void job_wait(job* job) { + if (!job) return; + while (!job->done) { mtx_lock(&state.lock); @@ -153,15 +128,8 @@ void job_wait(job* job) { thrd_yield(); } } -} -const char* job_get_error(job* job) { - return (char*) job->error; -} - -void job_free(job* job) { mtx_lock(&state.lock); - if (job->error) free(job->error); job->next = state.pool; state.pool = job; mtx_unlock(&state.lock); diff --git a/src/core/job.h b/src/core/job.h index bb82cef7..8c436790 100644 --- a/src/core/job.h +++ b/src/core/job.h @@ -5,13 +5,9 @@ #pragma once typedef struct job job; -typedef void fn_job(job* job, void* arg); +typedef void fn_job(void* arg); bool job_init(uint32_t workerCount); void job_destroy(void); job* job_start(fn_job* fn, void* arg); -void job_abort(job* job, const char* error); -void job_vabort(job* job, const char* format, va_list args); void job_wait(job* job); -const char* job_get_error(job* job); -void job_free(job* job);