summaryrefslogtreecommitdiff
path: root/sched.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@debian.org>2008-08-27 13:45:17 +0200
committerMichael Meskes <meskes@debian.org>2008-08-27 13:45:17 +0200
commitf06a98f0b468601fc1ab929b06a7962cca8614ea (patch)
treed1e64a0785f80b753f11d81a77f9cb27f86dcf0a /sched.c
Imported Upstream version 0.1
Diffstat (limited to 'sched.c')
-rw-r--r--sched.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/sched.c b/sched.c
new file mode 100644
index 0000000..be48e3c
--- /dev/null
+++ b/sched.c
@@ -0,0 +1,25 @@
+#include <time.h>
+#include <unistd.h>
+
+#include "sched.h"
+
+#define min(x, y) ((x) < (y)?(x) : (y))
+
+void sleep_untill_next_event(sched_t *psched, int n_sched)
+{
+ time_t now = time(NULL);
+ int loop;
+ int sleep_n = now + 3600;
+
+ for(loop=0; loop<n_sched; loop++)
+ {
+ time_t cur_next_schedule = psched[loop].last_run + psched[loop].interval;
+
+ sleep_n = min(sleep_n, cur_next_schedule - now);
+ if (sleep_n < 0)
+ sleep_n = 0;
+ }
+
+ if (sleep_n > 0)
+ sleep(sleep_n);
+}