Refactor, use new work queue helper

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2018-10-07 21:30:07 +02:00
1 parent 859c216347
commit 4870cab898
3 files changed
+21 -46

No files matched your search

+10 -25
View File
@@ -45,36 +45,16 @@
#include "tty.h"
#include "util.h"
#include "utmp-api.h"
#include "schedule.h"
#define RESPAWN_MAX 10 /* Prevent endless respawn of faulty services. */
static uev_t wq_timer;
static int wq_init = 0;
static struct wq work = {
.cb = service_worker,
};
static void svc_set_state(svc_t *svc, svc_state_t new);
/* Should be generic work, but currently only steps all services */
static void wq(uev_t *w, void *arg, int events)
{
if (UEV_ERROR == events) {
uev_timer_start(w);
return;
}
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_RUNTASK | SVC_TYPE_INETD);
}
static int schedule_wq(void)
{
if (!wq_init) {
wq_init =1;
return uev_timer_init(ctx, &wq_timer, wq, NULL, 100, 0);
}
return uev_timer_set(&wq_timer, 100, 0);
}
/**
* service_timeout_cb - libuev callback wrapper for service timeouts
* @w: Watcher
@@ -1228,7 +1208,7 @@ restart:
* waiting to running, other services may need to change state too.
*/
if (changed)
schedule_wq();
schedule_work(&work);
return 0;
}
@@ -1238,6 +1218,11 @@ void service_step_all(int types)
svc_foreach_type(types, service_step);
}
void service_worker(void *unused)
{
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_RUNTASK | SVC_TYPE_INETD);
}
/**
* svc_clean_runtask - Clear once flag of runtasks
*
+1
View File
@@ -36,6 +36,7 @@ void service_reload_dynamic (void);
int service_step (svc_t *svc);
void service_step_all (int types);
void service_worker (void *unused);
void service_bootstrap_cb (uev_t *w, void *arg, int events);
+10 -21
View File
@@ -36,25 +36,19 @@
#include "pid.h"
#include "util.h"
#include "cond.h"
#include "schedule.h"
/* Each svc_t needs a unique job# */
static int jobcounter = 1;
static TAILQ_HEAD(, svc) svc_list = TAILQ_HEAD_INITIALIZER(svc_list);
static TAILQ_HEAD(, svc) gc_list = TAILQ_HEAD_INITIALIZER(gc_list);
static uev_t gc_timer;
static int gc_init = 0;
static void gc(uev_t *w, void *arg, int events)
static void svc_gc(void *arg)
{
struct timespec now;
struct wq *work = (struct wq *)arg;
svc_t *svc, *next;
if (UEV_ERROR == events) {
uev_timer_start(w);
return;
}
clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
TAILQ_FOREACH_SAFE(svc, &gc_list, link, next) {
char cond[MAX_COND_LEN];
@@ -71,17 +65,7 @@ static void gc(uev_t *w, void *arg, int events)
}
if (!TAILQ_EMPTY(&gc_list))
uev_timer_set(&gc_timer, SVC_TERM_TIMEOUT, 0);
}
static int schedule_gc(int msec)
{
if (!gc_init) {
gc_init =1;
return uev_timer_init(ctx, &gc_timer, gc, NULL, msec, 0);
}
return uev_timer_set(&gc_timer, msec, 0);
schedule_work(work);
}
/**
@@ -131,6 +115,11 @@ svc_t *svc_new(char *cmd, int id, int type)
return svc;
}
static struct wq work = {
.cb = svc_gc,
.delay = SVC_TERM_TIMEOUT
};
/**
* svc_del - Mark a service object for deletion
* @svc: Pointer to an &svc_t object
@@ -144,7 +133,7 @@ int svc_del(svc_t *svc)
TAILQ_INSERT_TAIL(&gc_list, svc, link);
clock_gettime(CLOCK_MONOTONIC_COARSE, &svc->gc);
schedule_gc(SVC_TERM_TIMEOUT);
schedule_work(&work);
return 0;
}