diff options
author | default <nobody@localhost> | 2024-01-08 08:38:25 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2024-01-08 08:38:25 +0100 |
commit | b401cd23ff43a4afdcb3fad85f8c642680a82e95 (patch) | |
tree | 1e5351817050c92188c88e4e6c075350d994fb38 | |
parent | 0289860d04ee11d8b00a6a2bd3c59ce6f0d7ea10 (diff) |
Added some state flags for threads.
-rw-r--r-- | httpd.c | 16 | ||||
-rw-r--r-- | snac.h | 1 |
2 files changed, 15 insertions, 2 deletions
@@ -506,9 +506,9 @@ static void *job_thread(void *arg) for (;;) { xs *job = NULL; - job_wait(&job); + p_state->th_state[pid] = THST_WAIT; - srv_debug(2, xs_fmt("job thread %d wake up", pid)); + job_wait(&job); if (job == NULL) /* corrupted message? */ continue; @@ -520,6 +520,8 @@ static void *job_thread(void *arg) /* it's a socket */ FILE *f = NULL; + p_state->th_state[pid] = THST_IN; + xs_data_get(&f, job); if (f != NULL) @@ -527,10 +529,14 @@ static void *job_thread(void *arg) } else { /* it's a q_item */ + p_state->th_state[pid] = THST_OUT; + process_queue_item(job); } } + p_state->th_state[pid] = THST_STOP; + srv_debug(1, xs_fmt("job thread %d stopped", pid)); return NULL; @@ -556,6 +562,8 @@ static void *background_thread(void *arg) time_t t; int cnt = 0; + p_state->th_state[0] = THST_IN; + { xs *list = user_list(); char *p, *uid; @@ -588,6 +596,8 @@ static void *background_thread(void *arg) if (cnt == 0) { /* sleep 3 seconds */ + p_state->th_state[0] = THST_WAIT; + #ifdef USE_POLL_FOR_SLEEP poll(NULL, 0, 3 * 1000); #else @@ -603,6 +613,8 @@ static void *background_thread(void *arg) } } + p_state->th_state[0] = THST_STOP; + srv_log(xs_fmt("background thread stopped")); return NULL; @@ -51,6 +51,7 @@ typedef struct { time_t srv_start_time; /* start time */ int job_fifo_size; /* job fifo size */ int n_threads; /* number of configured threads */ + enum { THST_WAIT, THST_IN, THST_OUT, THST_STOP } th_state[MAX_THREADS]; } srv_state; void snac_log(snac *user, xs_str *str); |