commit b401cd2
default
·
2024-01-08 07:38:25 +0000 UTC
parent 0289860
Added some state flags for threads.
M
httpd.c
+14,
-2
1@@ -506,9 +506,9 @@ static void *job_thread(void *arg)
2 for (;;) {
3 xs *job = NULL;
4
5- job_wait(&job);
6+ p_state->th_state[pid] = THST_WAIT;
7
8- srv_debug(2, xs_fmt("job thread %d wake up", pid));
9+ job_wait(&job);
10
11 if (job == NULL) /* corrupted message? */
12 continue;
13@@ -520,6 +520,8 @@ static void *job_thread(void *arg)
14 /* it's a socket */
15 FILE *f = NULL;
16
17+ p_state->th_state[pid] = THST_IN;
18+
19 xs_data_get(&f, job);
20
21 if (f != NULL)
22@@ -527,10 +529,14 @@ static void *job_thread(void *arg)
23 }
24 else {
25 /* it's a q_item */
26+ p_state->th_state[pid] = THST_OUT;
27+
28 process_queue_item(job);
29 }
30 }
31
32+ p_state->th_state[pid] = THST_STOP;
33+
34 srv_debug(1, xs_fmt("job thread %d stopped", pid));
35
36 return NULL;
37@@ -556,6 +562,8 @@ static void *background_thread(void *arg)
38 time_t t;
39 int cnt = 0;
40
41+ p_state->th_state[0] = THST_IN;
42+
43 {
44 xs *list = user_list();
45 char *p, *uid;
46@@ -588,6 +596,8 @@ static void *background_thread(void *arg)
47 if (cnt == 0) {
48 /* sleep 3 seconds */
49
50+ p_state->th_state[0] = THST_WAIT;
51+
52 #ifdef USE_POLL_FOR_SLEEP
53 poll(NULL, 0, 3 * 1000);
54 #else
55@@ -603,6 +613,8 @@ static void *background_thread(void *arg)
56 }
57 }
58
59+ p_state->th_state[0] = THST_STOP;
60+
61 srv_log(xs_fmt("background thread stopped"));
62
63 return NULL;
M
snac.h
+1,
-0
1@@ -51,6 +51,7 @@ typedef struct {
2 time_t srv_start_time; /* start time */
3 int job_fifo_size; /* job fifo size */
4 int n_threads; /* number of configured threads */
5+ enum { THST_WAIT, THST_IN, THST_OUT, THST_STOP } th_state[MAX_THREADS];
6 } srv_state;
7
8 void snac_log(snac *user, xs_str *str);