mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
New thread for purge.
This commit is contained in:
parent
3462ecc950
commit
c7ff714710
2 changed files with 29 additions and 4 deletions
4
data.c
4
data.c
|
@ -1064,8 +1064,6 @@ void purge_all(void)
|
||||||
xs *list = user_list();
|
xs *list = user_list();
|
||||||
char *p, *uid;
|
char *p, *uid;
|
||||||
|
|
||||||
srv_debug(1, xs_fmt("purge start"));
|
|
||||||
|
|
||||||
p = list;
|
p = list;
|
||||||
while (xs_list_iter(&p, &uid)) {
|
while (xs_list_iter(&p, &uid)) {
|
||||||
if (user_open(&snac, uid)) {
|
if (user_open(&snac, uid)) {
|
||||||
|
@ -1073,6 +1071,4 @@ void purge_all(void)
|
||||||
user_free(&snac);
|
user_free(&snac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srv_debug(1, xs_fmt("purge end"));
|
|
||||||
}
|
}
|
||||||
|
|
29
httpd.c
29
httpd.c
|
@ -207,18 +207,37 @@ void term_handler(int s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void *purge_thread(void *arg)
|
||||||
|
/* spawned purge */
|
||||||
|
{
|
||||||
|
srv_log(xs_dup("purge start"));
|
||||||
|
|
||||||
|
purge_all();
|
||||||
|
|
||||||
|
srv_log(xs_dup("purge end"));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *queue_thread(void *arg)
|
static void *queue_thread(void *arg)
|
||||||
/* queue thread (queue management) */
|
/* queue thread (queue management) */
|
||||||
{
|
{
|
||||||
pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER;
|
||||||
|
time_t purge_time;
|
||||||
|
|
||||||
|
/* first purge time */
|
||||||
|
purge_time = time(NULL) + 15 * 60;
|
||||||
|
|
||||||
srv_log(xs_fmt("queue thread start"));
|
srv_log(xs_fmt("queue thread start"));
|
||||||
|
|
||||||
while (srv_running) {
|
while (srv_running) {
|
||||||
xs *list = user_list();
|
xs *list = user_list();
|
||||||
char *p, *uid;
|
char *p, *uid;
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
/* process queues for all users */
|
||||||
p = list;
|
p = list;
|
||||||
while (xs_list_iter(&p, &uid)) {
|
while (xs_list_iter(&p, &uid)) {
|
||||||
snac snac;
|
snac snac;
|
||||||
|
@ -229,6 +248,16 @@ static void *queue_thread(void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* time to purge? */
|
||||||
|
if ((t = time(NULL)) > purge_time) {
|
||||||
|
pthread_t pth;
|
||||||
|
|
||||||
|
pthread_create(&pth, NULL, purge_thread, NULL);
|
||||||
|
|
||||||
|
/* next purge time is tomorrow */
|
||||||
|
purge_time = t + 24 * 60 * 60;
|
||||||
|
}
|
||||||
|
|
||||||
/* sleep 3 seconds */
|
/* sleep 3 seconds */
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
|
Loading…
Reference in a new issue