diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-04-10 12:19:13 +1000 |
---|---|---|
committer | Geoff Levand <geoff@infradead.org> | 2013-04-10 10:49:20 -0700 |
commit | 37428306a270088bfcb1f94362a0fe5b7a5a888e (patch) | |
tree | 5d1aeca3eca44b68a8f8939e3bea44709a953aa9 /ui | |
parent | ee86a0bd989511319adf3467b41b5b2e1f486aa6 (diff) | |
download | petitboot-37428306a270088bfcb1f94362a0fe5b7a5a888e.zip petitboot-37428306a270088bfcb1f94362a0fe5b7a5a888e.tar.gz |
waiter: Don't rely on global variables to keep waiter state
Rather than defining the set of waiters (and pollfds) in waiter.c, add a
struct waitset to contain these. A waitset is created with
waitset_create, which is passed to the waiter_* functions.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Geoff Levand <geoff@infradead.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/ncurses/nc-cui.c | 14 | ||||
-rw-r--r-- | ui/ncurses/nc-cui.h | 1 | ||||
-rw-r--r-- | ui/twin/main-generic.c | 2 | ||||
-rw-r--r-- | ui/twin/pbt-client.c | 14 | ||||
-rw-r--r-- | ui/twin/pbt-client.h | 1 | ||||
-rw-r--r-- | ui/twin/pbt-scr.c | 6 | ||||
-rw-r--r-- | ui/twin/pbt-scr.h | 7 |
7 files changed, 29 insertions, 16 deletions
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index b9d8d79..a909b82 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -553,6 +553,7 @@ struct cui *cui_init(void* platform_info, cui->on_kexec = on_kexec; cui->timer.handle_timeout = cui_handle_timeout; cui->dry_run = dry_run; + cui->waitset = waitset_create(cui); /* Loop here for scripts that just started the server. */ @@ -595,18 +596,19 @@ retry_start: atexit(nc_atexit); nc_start(); - waiter_register(discover_client_get_fd(client), WAIT_IN, - cui_client_process_socket, client); + waiter_register(cui->waitset, discover_client_get_fd(client), WAIT_IN, + cui_client_process_socket, client); - waiter_register(STDIN_FILENO, WAIT_IN, cui_process_key, cui); + waiter_register(cui->waitset, STDIN_FILENO, WAIT_IN, + cui_process_key, cui); if (js_map) { cui->pjs = pjs_init(cui, js_map); if (cui->pjs) - waiter_register(pjs_get_fd(cui->pjs), WAIT_IN, - cui_process_js, cui); + waiter_register(cui->waitset, pjs_get_fd(cui->pjs), + WAIT_IN, cui_process_js, cui); } return cui; @@ -638,7 +640,7 @@ int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item) cui->current->post(cui->current); while (1) { - int result = waiter_poll(); + int result = waiter_poll(cui->waitset); if (result < 0 && errno != EINTR) { pb_log("%s: poll: %s\n", __func__, strerror(errno)); diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index 90eef1c..ddbf27f 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -55,6 +55,7 @@ struct cui { struct nc_scr *current; struct pmenu *main; struct ui_timer timer; + struct waitset *waitset; struct pjs *pjs; void *platform_info; unsigned int default_item; diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c index 91a525b..8ed46b7 100644 --- a/ui/twin/main-generic.c +++ b/ui/twin/main-generic.c @@ -215,7 +215,7 @@ static int kexec_cb(struct pbt_client *client, struct pb_opt_data *opt_data) static int run(struct pbt_client *client) { while (1) { - int result = waiter_poll(); + int result = waiter_poll(client->waitset); if (result < 0 && errno != EINTR) { pb_log("%s: poll: %s\n", __func__, strerror(errno)); diff --git a/ui/twin/pbt-client.c b/ui/twin/pbt-client.c index 6a4d863..8eba0a2 100644 --- a/ui/twin/pbt-client.c +++ b/ui/twin/pbt-client.c @@ -281,11 +281,14 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, talloc_set_destructor(pbt_client, (void *)pbt_client_destructor); + pbt_client->waitset = waitset_create(pbt_client); + pbt_client->sig = "pbt_client"; pbt_client->kexec_cb = kexec_cb; pbt_client->dry_run = dry_run; - pbt_client->frame.scr = pbt_scr_init(pbt_client, backend, width, height, - NULL, NULL); + pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset, + backend, width, height, NULL, NULL); + if (!pbt_client->frame.scr) goto fail_scr_init; @@ -329,9 +332,10 @@ retry_start: goto fail_client_init; } - waiter_register(discover_client_get_fd(pbt_client->discover_client), - WAIT_IN, (waiter_cb)discover_client_process, - pbt_client->discover_client); + waiter_register(pbt_client->waitset, + discover_client_get_fd(pbt_client->discover_client), + WAIT_IN, (waiter_cb)discover_client_process, + pbt_client->discover_client); return pbt_client; diff --git a/ui/twin/pbt-client.h b/ui/twin/pbt-client.h index 014d5b2..6c35920 100644 --- a/ui/twin/pbt-client.h +++ b/ui/twin/pbt-client.h @@ -49,6 +49,7 @@ struct pbt_client { struct pbt_frame frame; struct discover_client *discover_client; + struct waitset *waitset; }; struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, diff --git a/ui/twin/pbt-scr.c b/ui/twin/pbt-scr.c index 3a5a70b..8532bc1 100644 --- a/ui/twin/pbt-scr.c +++ b/ui/twin/pbt-scr.c @@ -368,7 +368,9 @@ static void pbt_scr_destructor(struct pbt_scr *scr) memset(scr, 0, sizeof(*scr)); } -struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend, +struct pbt_scr *pbt_scr_init(void *talloc_ctx, + struct waitset *waitset, + enum pbt_twin_backend backend, unsigned int width, unsigned int height, const char *filename_background, twin_bool_t (*scr_event_cb)(twin_screen_t *tscreen, @@ -441,7 +443,7 @@ struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend, assert(waiter_fd != -1); - waiter_register(waiter_fd, WAIT_IN, (void *)pbt_twin_waiter_cb, + waiter_register(waitset, waiter_fd, WAIT_IN, (void *)pbt_twin_waiter_cb, &scr->twin_ctx); return scr; diff --git a/ui/twin/pbt-scr.h b/ui/twin/pbt-scr.h index c075aad..1198a59 100644 --- a/ui/twin/pbt-scr.h +++ b/ui/twin/pbt-scr.h @@ -18,6 +18,8 @@ #if !defined(_PBT_SCR_H) #define _PBT_SCR_H +#include <waiter/waiter.h> + #include <libtwin/twin.h> #include <libtwin/twin_jpeg.h> #include <libtwin/twin_linux_mouse.h> @@ -137,7 +139,8 @@ struct pbt_scr { twin_pixmap_t *cursor; }; -struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend, +struct pbt_scr *pbt_scr_init(void *talloc_ctx, struct waitset *waitset, + enum pbt_twin_backend backend, unsigned int width, unsigned int height, const char *filename_background, twin_bool_t (*scr_event_cb)(twin_screen_t *tscreen, @@ -171,4 +174,4 @@ void pbt_window_redraw(twin_window_t *twindow); _p->height) -#endif
\ No newline at end of file +#endif |