commit 60c50c0
default
·
2023-02-22 09:35:26 +0000 UTC
parent 295507f
Create sleep mutex and cond variable only once.
1 files changed,
+10,
-5
M
httpd.c
M
httpd.c
+10,
-5
1@@ -342,6 +342,9 @@ static void *job_thread(void *arg)
2 return NULL;
3 }
4
5+/* background thread sleep control */
6+static pthread_mutex_t sleep_mutex;
7+static pthread_cond_t sleep_cond;
8
9 static void *background_thread(void *arg)
10 /* background thread (queue management and other things) */
11@@ -392,16 +395,14 @@ static void *background_thread(void *arg)
12 #ifdef USE_POLL_FOR_SLEEP
13 poll(NULL, 0, 3 * 1000);
14 #else
15- pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER;
16- pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER;
17 struct timespec ts;
18
19 clock_gettime(CLOCK_REALTIME, &ts);
20 ts.tv_sec += 3;
21
22- pthread_mutex_lock(&dummy_mutex);
23- while (pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &ts) == 0);
24- pthread_mutex_unlock(&dummy_mutex);
25+ pthread_mutex_lock(&sleep_mutex);
26+ while (pthread_cond_timedwait(&sleep_cond, &sleep_mutex, &ts) == 0);
27+ pthread_mutex_unlock(&sleep_mutex);
28 #endif
29 }
30 }
31@@ -449,6 +450,10 @@ void httpd(void)
32 sem_init(&job_sem, 0, 0);
33 job_fifo = xs_list_new();
34
35+ /* initialize sleep control */
36+ pthread_mutex_init(&sleep_mutex, NULL);
37+ pthread_cond_init(&sleep_cond, NULL);
38+
39 n_threads = xs_number_get(xs_dict_get(srv_config, "num_threads"));
40
41 #ifdef _SC_NPROCESSORS_ONLN