summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-05-07 17:55:47 +0200
committerGravatar default2023-05-07 17:55:47 +0200
commit0a93eae0a87764f23aeec40c06202770d25f48f1 (patch)
tree4fecf515bae361bec65e951161f68f1c605f4413
parentBumped version. (diff)
parentMerge pull request 'Use named semaphores' (#32) from saagarjha/snac2:master i... (diff)
downloadpenes-snac2-0a93eae0a87764f23aeec40c06202770d25f48f1.tar.gz
penes-snac2-0a93eae0a87764f23aeec40c06202770d25f48f1.tar.xz
penes-snac2-0a93eae0a87764f23aeec40c06202770d25f48f1.zip
Merge branch 'master' of grunfink-codeberg:grunfink/snac2
-rw-r--r--httpd.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/httpd.c b/httpd.c
index fe93727..7a25b84 100644
--- a/httpd.c
+++ b/httpd.c
@@ -299,7 +299,7 @@ void term_handler(int s)
299static pthread_mutex_t job_mutex; 299static pthread_mutex_t job_mutex;
300 300
301/* semaphre to trigger job processing */ 301/* semaphre to trigger job processing */
302static sem_t job_sem; 302static sem_t *job_sem;
303 303
304/* fifo of jobs */ 304/* fifo of jobs */
305xs_list *job_fifo = NULL; 305xs_list *job_fifo = NULL;
@@ -332,7 +332,7 @@ void job_post(const xs_val *job, int urgent)
332 } 332 }
333 333
334 /* ask for someone to attend it */ 334 /* ask for someone to attend it */
335 sem_post(&job_sem); 335 sem_post(job_sem);
336} 336}
337 337
338 338
@@ -341,7 +341,7 @@ void job_wait(xs_val **job)
341{ 341{
342 *job = NULL; 342 *job = NULL;
343 343
344 if (sem_wait(&job_sem) == 0) { 344 if (sem_wait(job_sem) == 0) {
345 /* lock the mutex */ 345 /* lock the mutex */
346 pthread_mutex_lock(&job_mutex); 346 pthread_mutex_lock(&job_mutex);
347 347
@@ -352,6 +352,10 @@ void job_wait(xs_val **job)
352 /* unlock the mutex */ 352 /* unlock the mutex */
353 pthread_mutex_unlock(&job_mutex); 353 pthread_mutex_unlock(&job_mutex);
354 } 354 }
355
356 if (!*job) {
357 sem_close(job_sem);
358 }
355} 359}
356 360
357 361
@@ -362,7 +366,7 @@ void job_wait(xs_val **job)
362static void *job_thread(void *arg) 366static void *job_thread(void *arg)
363/* job thread */ 367/* job thread */
364{ 368{
365 int pid = (char *) arg - (char *) 0x0; 369 int pid = (int)(uintptr_t)arg;
366 370
367 srv_debug(1, xs_fmt("job thread %d started", pid)); 371 srv_debug(1, xs_fmt("job thread %d started", pid));
368 372
@@ -503,7 +507,7 @@ void httpd(void)
503 507
504 /* initialize the job control engine */ 508 /* initialize the job control engine */
505 pthread_mutex_init(&job_mutex, NULL); 509 pthread_mutex_init(&job_mutex, NULL);
506 sem_init(&job_sem, 0, 0); 510 job_sem = sem_open("/job", O_CREAT, 0644, 0);
507 job_fifo = xs_list_new(); 511 job_fifo = xs_list_new();
508 512
509 /* initialize sleep control */ 513 /* initialize sleep control */