summaryrefslogtreecommitdiffstats
path: root/ui/common
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-05-21 12:43:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-06-24 12:52:50 +0800
commit293fca73b2fe077e7780c1a42216a3db41a6e737 (patch)
tree98001a1496253693c7da5a1a05ce06c421fdbe04 /ui/common
parent2723662cabd4d34d4155ab5d6668c591a20a086b (diff)
downloadpetitboot-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/common')
-rw-r--r--ui/common/timer.c90
-rw-r--r--ui/common/timer.h11
2 files changed, 21 insertions, 80 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
OpenPOWER on IntegriCloud