diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-05-21 12:43:36 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-06-24 12:52:50 +0800 |
commit | 293fca73b2fe077e7780c1a42216a3db41a6e737 (patch) | |
tree | 98001a1496253693c7da5a1a05ce06c421fdbe04 /ui | |
parent | 2723662cabd4d34d4155ab5d6668c591a20a086b (diff) | |
download | petitboot-293fca73b2fe077e7780c1a42216a3db41a6e737.zip petitboot-293fca73b2fe077e7780c1a42216a3db41a6e737.tar.gz |
ui: implement timers with waitsets
A temporary change to the timers; we'll eventually remove these from the
ui code.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/common/timer.c | 90 | ||||
-rw-r--r-- | ui/common/timer.h | 11 | ||||
-rw-r--r-- | ui/ncurses/generic-main.c | 4 | ||||
-rw-r--r-- | ui/ncurses/nc-cui.c | 2 | ||||
-rw-r--r-- | ui/twin/main-generic.c | 5 |
5 files changed, 21 insertions, 91 deletions
diff --git a/ui/common/timer.c b/ui/common/timer.c index 954a18a..3c1e833 100644 --- a/ui/common/timer.c +++ b/ui/common/timer.c @@ -33,71 +33,37 @@ * @seconds: The final timeout value in seconds. */ -void ui_timer_init(struct ui_timer *timer, unsigned int seconds) +void ui_timer_init(struct waitset *waitset, struct ui_timer *timer, + unsigned int seconds) { pb_log("%s: %u\n", __func__, seconds); - assert(!timer->disabled); timer->timeout = seconds; + timer->waitset = waitset; } /** - * ui_timer_next - Calculate the next timer interval. + * ui_timer_kick - Kickstart the next timer interval. */ -static unsigned int ui_timer_next(unsigned int seconds) +static int timer_cb(void *arg) { - unsigned int next; - - if (seconds == 0) { - next = 0; - goto done; - } - - if (seconds <= 10) { - next = 1; - goto done; - } - - if (seconds <= 60) { - next = seconds % 5; - next = next ? next : 5; - goto done; - } + struct ui_timer *timer = arg; - next = seconds % 10; - next = next ? next : 10; - -done: - pb_log("%s: %u = %u\n", __func__, seconds, next); - return next; + timer->handle_timeout(timer); + timer->waiter = 0; + return 0; } -/** - * ui_timer_kick - Kickstart the next timer interval. - */ - void ui_timer_kick(struct ui_timer *timer) { - unsigned int next; - - if(timer->disabled) - return; - if (timer->update_display) timer->update_display(timer, timer->timeout); - next = ui_timer_next(timer->timeout); - timer->timeout -= next; - - if (next) { - alarm(next); - return; - } - - pb_log("%s: timed out\n", __func__); + if (timer->waiter) + waiter_remove(timer->waiter); - ui_timer_disable(timer); - timer->handle_timeout(timer); + timer->waiter = waiter_register_timeout(timer->waitset, + timer->timeout * 1000, timer_cb, timer); } /** @@ -106,34 +72,10 @@ void ui_timer_kick(struct ui_timer *timer) void ui_timer_disable(struct ui_timer *timer) { - if (timer->disabled) + if (!timer->waiter) return; pb_log("%s\n", __func__); - timer->disabled = 1; - timer->timeout = UINT_MAX; - alarm(0); -} - -/** - * ui_timer_sigalrm - * - * Called at SIGALRM. - */ - -void ui_timer_sigalrm(struct ui_timer *timer) -{ - timer->signaled = 1; -} - -/** - * ui_timer_process_sig - Process a timer signal - */ - -void ui_timer_process_sig(struct ui_timer *timer) -{ - while (timer->signaled) { - timer->signaled = 0; - ui_timer_kick(timer); - } + waiter_remove(timer->waiter); + timer->waiter = NULL; } diff --git a/ui/common/timer.h b/ui/common/timer.h index 781b442..7b36512 100644 --- a/ui/common/timer.h +++ b/ui/common/timer.h @@ -19,7 +19,7 @@ #if !defined(_PB_UI_TIMER_H) #define _PB_UI_TIMER_H -#include <signal.h> +#include <waiter/waiter.h> /** * struct ui_timer - UI timeout. @@ -27,16 +27,15 @@ struct ui_timer { unsigned int timeout; - unsigned int disabled; - sig_atomic_t signaled; + struct waiter *waiter; + struct waitset *waitset; void (*update_display)(struct ui_timer *timer, unsigned int timeout); void (*handle_timeout)(struct ui_timer *timer); }; -void ui_timer_init(struct ui_timer *timer, unsigned int seconds); +void ui_timer_init(struct waitset *set, struct ui_timer *timer, + unsigned int seconds); void ui_timer_kick(struct ui_timer *timer); void ui_timer_disable(struct ui_timer *timer); -void ui_timer_sigalrm(struct ui_timer *timer); -void ui_timer_process_sig(struct ui_timer *timer); #endif diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 365034c..560e3e5 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -180,10 +180,6 @@ static void sig_handler(int signum) DBGS("%d\n", signum); switch (signum) { - case SIGALRM: - if (pb.cui) - ui_timer_sigalrm(&pb.cui->timer); - break; case SIGWINCH: if (pb.cui) cui_resize(pb.cui); diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index ef3fd23..bd4f6b8 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -623,8 +623,6 @@ int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item) if (cui->abort) break; - ui_timer_process_sig(&cui->timer); - while (cui->resize) { cui->resize = 0; cui_handle_resize(cui); diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index c9cb492..fcda709 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -212,8 +212,6 @@ static int run(struct pbt_client *client) if (client->signal_data.abort) break; - ui_timer_process_sig(&client->signal_data.timer); - while (client->signal_data.resize) { client->signal_data.resize = 0; pbt_client_resize(client); @@ -245,9 +243,6 @@ static void sig_handler(int signum) return; switch (signum) { - case SIGALRM: - ui_timer_sigalrm(&sd->timer); - break; case SIGWINCH: sd->resize = 1; break; |