#define _GNU_SOURCE
#include <stdlib.h>
+#include <stdint.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#define sig_monitor(to,cb,arg) (cb(0,arg))
#endif
+#define EVENT_TIMEOUT_TOP ((uint64_t)-1)
+#define EVENT_TIMEOUT_CHILD ((uint64_t)10000)
+
/** Internal shortcut for callback */
typedef void (*job_cb_t)(int, void*, void *, void*);
{
struct events *next;
struct sd_event *event;
+ uint64_t timeout;
unsigned runs: 1;
};
{
struct events *events = arg;
if (!signum)
- sd_event_run(events->event, (uint64_t) -1);
+ sd_event_run(events->event, events->timeout);
}
/**
struct thread **prv;
struct job *job;
struct events *events;
+ uint64_t evto;
/* initialize description of itself and link it in the list */
me->tid = pthread_self();
me->lowered = 0;
me->waits = 0;
me->upper = current;
- if (current)
+ if (current) {
current->lowered = 1;
- else
+ evto = EVENT_TIMEOUT_CHILD;
+ } else {
+ started++;
sig_monitor_init_timeouts();
- current = (struct thread*)me;
+ evto = EVENT_TIMEOUT_TOP;
+ }
me->next = threads;
threads = (struct thread*)me;
- started++;
+ current = (struct thread*)me;
NOTICE("job thread starting %d(/%d) %s", started, allowed, me->upper ? "child" : "parent");
if (events) {
/* run the events */
events->runs = 1;
+ events->timeout = evto;
me->events = events;
pthread_mutex_unlock(&mutex);
sig_monitor(0, events_call, events);
NOTICE("job thread stoping %d(/%d) %s", started, allowed, me->upper ? "child" : "parent");
/* unlink the current thread and cleanup */
- started--;
prv = &threads;
while (*prv != me)
prv = &(*prv)->next;
*prv = me->next;
current = me->upper;
- if (current)
+ if (current) {
current->lowered = 0;
- else
+ } else {
sig_monitor_clean_timeouts();
+ started--;
+ }
}
/**