diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 35 |
1 files changed, 24 insertions, 11 deletions
| @@ -17,6 +17,10 @@ | |||
| 17 | 17 | ||
| 18 | #include <sys/resource.h> // for getrlimit() | 18 | #include <sys/resource.h> // for getrlimit() |
| 19 | 19 | ||
| 20 | #ifdef USE_POLL_FOR_SLEEP | ||
| 21 | #include <poll.h> | ||
| 22 | #endif | ||
| 23 | |||
| 20 | 24 | ||
| 21 | /* nodeinfo 2.0 template */ | 25 | /* nodeinfo 2.0 template */ |
| 22 | const char *nodeinfo_2_0_template = "" | 26 | const char *nodeinfo_2_0_template = "" |
| @@ -338,6 +342,7 @@ static void *job_thread(void *arg) | |||
| 338 | return NULL; | 342 | return NULL; |
| 339 | } | 343 | } |
| 340 | 344 | ||
| 345 | #include <poll.h> | ||
| 341 | 346 | ||
| 342 | static void *background_thread(void *arg) | 347 | static void *background_thread(void *arg) |
| 343 | /* background thread (queue management and other things) */ | 348 | /* background thread (queue management and other things) */ |
| @@ -351,6 +356,7 @@ static void *background_thread(void *arg) | |||
| 351 | 356 | ||
| 352 | while (srv_running) { | 357 | while (srv_running) { |
| 353 | time_t t; | 358 | time_t t; |
| 359 | int cnt = 0; | ||
| 354 | 360 | ||
| 355 | { | 361 | { |
| 356 | xs *list = user_list(); | 362 | xs *list = user_list(); |
| @@ -362,14 +368,14 @@ static void *background_thread(void *arg) | |||
| 362 | snac snac; | 368 | snac snac; |
| 363 | 369 | ||
| 364 | if (user_open(&snac, uid)) { | 370 | if (user_open(&snac, uid)) { |
| 365 | process_user_queue(&snac); | 371 | cnt += process_user_queue(&snac); |
| 366 | user_free(&snac); | 372 | user_free(&snac); |
| 367 | } | 373 | } |
| 368 | } | 374 | } |
| 369 | } | 375 | } |
| 370 | 376 | ||
| 371 | /* global queue */ | 377 | /* global queue */ |
| 372 | process_queue(); | 378 | cnt += process_queue(); |
| 373 | 379 | ||
| 374 | /* time to purge? */ | 380 | /* time to purge? */ |
| 375 | if ((t = time(NULL)) > purge_time) { | 381 | if ((t = time(NULL)) > purge_time) { |
| @@ -381,17 +387,24 @@ static void *background_thread(void *arg) | |||
| 381 | job_post(q_item); | 387 | job_post(q_item); |
| 382 | } | 388 | } |
| 383 | 389 | ||
| 384 | /* sleep 3 seconds */ | 390 | if (cnt == 0) { |
| 385 | pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER; | 391 | /* sleep 3 seconds */ |
| 386 | pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER; | 392 | |
| 387 | struct timespec ts; | 393 | #ifdef USE_POLL_FOR_SLEEP |
| 394 | poll(NULL, 0, 3 * 1000); | ||
| 395 | #else | ||
| 396 | pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 397 | pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER; | ||
| 398 | struct timespec ts; | ||
| 388 | 399 | ||
| 389 | clock_gettime(CLOCK_REALTIME, &ts); | 400 | clock_gettime(CLOCK_REALTIME, &ts); |
| 390 | ts.tv_sec += 3; | 401 | ts.tv_sec += 3; |
| 391 | 402 | ||
| 392 | pthread_mutex_lock(&dummy_mutex); | 403 | pthread_mutex_lock(&dummy_mutex); |
| 393 | while (pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &ts) == 0); | 404 | while (pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &ts) == 0); |
| 394 | pthread_mutex_unlock(&dummy_mutex); | 405 | pthread_mutex_unlock(&dummy_mutex); |
| 406 | #endif | ||
| 407 | } | ||
| 395 | } | 408 | } |
| 396 | 409 | ||
| 397 | srv_log(xs_fmt("background thread stopped")); | 410 | srv_log(xs_fmt("background thread stopped")); |