commit aa1524b

default  ·  2024-01-07 10:13:59 +0000 UTC
parent 3d1f604
Better behaviour on broken queue items.
2 files changed,  +14, -8
+13, -7
 1@@ -451,14 +451,17 @@ void job_post(const xs_val *job, int urgent)
 2                 job_fifo = xs_list_append(job_fifo, job);
 3 
 4             p_stat->job_fifo_size++;
 5+
 6+            srv_debug(2, xs_fmt(
 7+                "job_fifo sizes: %d %08x", p_stat->job_fifo_size, xs_size(job_fifo)));
 8         }
 9 
10         /* unlock the mutex */
11         pthread_mutex_unlock(&job_mutex);
12-    }
13 
14-    /* ask for someone to attend it */
15-    sem_post(job_sem);
16+        /* ask for someone to attend it */
17+        sem_post(job_sem);
18+    }
19 }
20 
21 
22@@ -502,9 +505,12 @@ static void *job_thread(void *arg)
23 
24         srv_debug(2, xs_fmt("job thread %d wake up", pid));
25 
26-        if (job == NULL)
27-            break;
28+        if (job == NULL) /* corrupted message? */
29+            continue;
30 
31+        if (xs_type(job) == XSTYPE_FALSE) /* special message: exit */
32+            break;
33+        else
34         if (xs_type(job) == XSTYPE_DATA) {
35             /* it's a socket */
36             FILE *f = NULL;
37@@ -703,9 +709,9 @@ void httpd(void)
38 
39     p_stat->srv_running = 0;
40 
41-    /* send as many empty jobs as working threads */
42+    /* send as many exit jobs as working threads */
43     for (n = 1; n < p_stat->n_threads; n++)
44-        job_post(NULL, 0);
45+        job_post(xs_stock_false, 0);
46 
47     /* wait for all the threads to exit */
48     for (n = 0; n < p_stat->n_threads; n++)
+1, -1
1@@ -1 +1 @@
2-/* 3e906b28aaa910cd79dd5eb1d88fda82201d28de 2024-01-04T09:20:12+01:00 */
3+/* 72caf9fc60c0b90f39a3c62b238d1c9663d109bc 2024-01-07T09:26:08+01:00 */