Use pause(2) to suspend timer ticking

See #4 for discussion about waiting for signals, instead of incrementing
timecount with zero value.
This commit is contained in:
Simon Lieb 2016-10-20 00:24:09 +02:00 committed by Ivan Tham
parent 906a6caa13
commit 0af77c1282

17
spt.c
View File

@ -24,7 +24,7 @@ typedef struct {
#include "config.h" #include "config.h"
static int i, timecount, inc; static int i, timecount, suspend;
/* function declarations */ /* function declarations */
static void die(const char *errstr, ...); static void die(const char *errstr, ...);
@ -95,7 +95,8 @@ void
toggle(int sigint) { toggle(int sigint) {
if (signal(SIGUSR2, SIG_IGN) != SIG_IGN) if (signal(SIGUSR2, SIG_IGN) != SIG_IGN)
signal(SIGUSR2, toggle); signal(SIGUSR2, toggle);
inc ^= 1;
suspend ^= 1;
} }
void void
@ -107,7 +108,7 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
inc = 1; suspend = 0;
ARGBEGIN { ARGBEGIN {
case 'e': case 'e':
@ -131,8 +132,14 @@ main(int argc, char *argv[])
for (i = 0; ; i = (i + 1) % LEN(timers)) { for (i = 0; ; i = (i + 1) % LEN(timers)) {
notify_send(timers[i].cmt); notify_send(timers[i].cmt);
for (timecount = 0; timecount < timers[i].tmr; timecount += inc) timecount = 0;
sleep(1); while (timecount < timers[i].tmr)
if (suspend)
pause();
else {
sleep(1);
timecount++;
}
} }
return 0; return 0;