File: sched.c

package info (click to toggle)
acpitail 0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 108 kB
  • sloc: ansic: 338; makefile: 23
file content (25 lines) | stat: -rw-r--r-- 469 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
}