// XXX sigwait instead of signal handler... #include #include "common.h" #include "consts.h" #include "config.h" #include "backlight.h" static pid_t keypress_pid; uint64_t time_since_press(void) { struct timeval now; uint64_t now_usec; uint64_t press_usec; uint64_t diff; gettimeofday(&now, NULL); now_usec = now.tv_sec * 1000000L; now_usec += now.tv_usec; press_usec = last_press->tv_sec * 1000000L; press_usec += last_press->tv_usec; diff = now_usec - press_usec; return diff; } void handler(int _) { if (time_since_press() > BACKLIGHT_TIME) { backlight_off(); } else { backlight_on(); usleep(BACKLIGHT_TIME); raise(SIGCONT); } } void light_thread() { signal(SIGCONT, handler); for (;;) pause(); __builtin_unreachable(); }