diff options
author | default <nobody@localhost> | 2023-02-10 11:23:42 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2023-02-10 11:23:42 +0100 |
commit | d4979d9403c7478baba2bb3c3bae313ee86ea17a (patch) | |
tree | f134cb53a0b64b1b7f75c302b2f1fac195503fe9 | |
parent | 3ba3815b649a35ac32abab3c2b28ceae38e93c27 (diff) |
Added more job_fifo concurrency protections.
-rw-r--r-- | httpd.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -257,7 +257,8 @@ void job_post(const xs_val *job) pthread_mutex_lock(&job_mutex); /* add to the fifo */ - job_fifo = xs_list_append(job_fifo, job); + if (job_fifo != NULL) + job_fifo = xs_list_append(job_fifo, job); /* unlock the mutex */ pthread_mutex_unlock(&job_mutex); @@ -278,7 +279,8 @@ void job_wait(xs_val **job) pthread_mutex_lock(&job_mutex); /* dequeue */ - job_fifo = xs_list_shift(job_fifo, job); + if (job_fifo != NULL) + job_fifo = xs_list_shift(job_fifo, job); /* unlock the mutex */ pthread_mutex_unlock(&job_mutex); @@ -465,7 +467,9 @@ void httpd(void) for (n = 0; n < n_threads; n++) pthread_join(threads[n], NULL); + pthread_mutex_lock(&job_mutex); job_fifo = xs_free(job_fifo); + pthread_mutex_unlock(&job_mutex); srv_log(xs_fmt("httpd stop %s:%d", address, port)); } |