Added more job_fifo concurrency protections.

This commit is contained in:
default 2023-02-10 11:23:42 +01:00
parent 3ba3815b64
commit d4979d9403

View file

@ -257,6 +257,7 @@ void job_post(const xs_val *job)
pthread_mutex_lock(&job_mutex); pthread_mutex_lock(&job_mutex);
/* add to the fifo */ /* add to the fifo */
if (job_fifo != NULL)
job_fifo = xs_list_append(job_fifo, job); job_fifo = xs_list_append(job_fifo, job);
/* unlock the mutex */ /* unlock the mutex */
@ -278,6 +279,7 @@ void job_wait(xs_val **job)
pthread_mutex_lock(&job_mutex); pthread_mutex_lock(&job_mutex);
/* dequeue */ /* dequeue */
if (job_fifo != NULL)
job_fifo = xs_list_shift(job_fifo, job); job_fifo = xs_list_shift(job_fifo, job);
/* unlock the mutex */ /* unlock the mutex */
@ -465,7 +467,9 @@ void httpd(void)
for (n = 0; n < n_threads; n++) for (n = 0; n < n_threads; n++)
pthread_join(threads[n], NULL); pthread_join(threads[n], NULL);
pthread_mutex_lock(&job_mutex);
job_fifo = xs_free(job_fifo); job_fifo = xs_free(job_fifo);
pthread_mutex_unlock(&job_mutex);
srv_log(xs_fmt("httpd stop %s:%d", address, port)); srv_log(xs_fmt("httpd stop %s:%d", address, port));
} }