commit 5036cb5

default  ·  2023-03-02 11:38:02 +0000 UTC
parent e705e5c
Connection jobs are treated as urgent.
4 files changed,  +13, -9
M data.c
M snac.h
+1, -1
1@@ -1316,7 +1316,7 @@ int process_queue(void)
2         xs *q_item = dequeue(fn);
3 
4         if (q_item != NULL) {
5-            job_post(q_item);
6+            job_post(q_item, 0);
7             cnt++;
8         }
9     }
M data.c
+1, -1
1@@ -1497,7 +1497,7 @@ void enqueue_output_raw(const char *keyid, const char *seckey,
2 
3     /* if it's to be sent right now, bypass the disk queue and post the job */
4     if (retries == 0 && job_fifo_ready())
5-        job_post(qmsg);
6+        job_post(qmsg, 0);
7     else {
8         qmsg = _enqueue_put(fn, qmsg);
9         srv_debug(1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
+10, -6
 1@@ -262,7 +262,7 @@ int job_fifo_ready(void)
 2 }
 3 
 4 
 5-void job_post(const xs_val *job)
 6+void job_post(const xs_val *job, int urgent)
 7 /* posts a job for the threads to process it */
 8 {
 9     if (job != NULL) {
10@@ -270,8 +270,12 @@ void job_post(const xs_val *job)
11         pthread_mutex_lock(&job_mutex);
12 
13         /* add to the fifo */
14-        if (job_fifo != NULL)
15-            job_fifo = xs_list_append(job_fifo, job);
16+        if (job_fifo != NULL) {
17+            if (urgent)
18+                job_fifo = xs_list_insert(job_fifo, 0, job);
19+            else
20+                job_fifo = xs_list_append(job_fifo, job);
21+        }
22 
23         /* unlock the mutex */
24         pthread_mutex_unlock(&job_mutex);
25@@ -386,7 +390,7 @@ static void *background_thread(void *arg)
26 
27             xs *q_item = xs_dict_new();
28             q_item = xs_dict_append(q_item, "type", "purge");
29-            job_post(q_item);
30+            job_post(q_item, 0);
31         }
32 
33         if (cnt == 0) {
34@@ -485,7 +489,7 @@ void httpd(void)
35 
36             if (f != NULL) {
37                 xs *job = xs_data_new(&f, sizeof(FILE *));
38-                job_post(job);
39+                job_post(job, 1);
40             }
41             else
42                 break;
43@@ -496,7 +500,7 @@ void httpd(void)
44 
45     /* send as many empty jobs as working threads */
46     for (n = 1; n < n_threads; n++)
47-        job_post(NULL);
48+        job_post(NULL, 0);
49 
50     /* wait for all the threads to exit */
51     for (n = 0; n < n_threads; n++)
M snac.h
+1, -1
1@@ -218,5 +218,5 @@ int adduser(const char *uid);
2 int resetpwd(snac *snac);
3 
4 int job_fifo_ready(void);
5-void job_post(const xs_val *job);
6+void job_post(const xs_val *job, int urgent);
7 void job_wait(xs_val **job);