From bb5d72410bf9a3a997ade1e8760b8f240d32af0d Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 24 Feb 2020 14:24:48 +0000 Subject: fetchers: Rework the about, data, file, and resource fetcher poll loop This simplifies the poll loops a little more and makes me less worried that some other corner case will bite us in the future. Signed-off-by: Daniel Silverstone --- content/fetchers/file.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'content/fetchers/file.c') diff --git a/content/fetchers/file.c b/content/fetchers/file.c index ede001faf..bf2cc3282 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -195,7 +195,6 @@ static void fetch_file_free(void *ctx) struct fetch_file_context *c = ctx; nsurl_unref(c->url); free(c->path); - RING_REMOVE(ring, c); free(ctx); } @@ -791,14 +790,13 @@ static void fetch_file_process(struct fetch_file_context *ctx) /** callback to poll for additional file fetch contents */ static void fetch_file_poll(lwc_string *scheme) { - struct fetch_file_context *c, *next; - bool was_last_item = false; + struct fetch_file_context *c, *save_ring = NULL; - if (ring == NULL) return; + while (ring != NULL) { + /* Take the first entry from the ring */ + c = ring; + RING_REMOVE(ring, c); - /* Iterate over ring, processing each pending fetch */ - c = ring; - do { /* Ignore fetches that have been flagged as locked. * This allows safe re-entrant calls to this function. * Re-entrancy can occur if, as a result of a callback, @@ -806,7 +804,7 @@ static void fetch_file_poll(lwc_string *scheme) * again. */ if (c->locked == true) { - next = c->r_next; + RING_INSERT(save_ring, c); continue; } @@ -816,32 +814,16 @@ static void fetch_file_poll(lwc_string *scheme) fetch_file_process(c); } - /* Compute next fetch item at the last possible moment as - * processing this item may have added to the ring. - */ - next = c->r_next; - was_last_item = next == c; - + /* And now finish */ fetch_remove_from_queues(c->fetchh); fetch_free(c->fetchh); - /* Having called into the fetch machinery, our ring might - * have been updated - */ - if (was_last_item) { - /* We were previously the last item in the ring - * so let's reset to the head of the ring - * and try again - */ - c = ring; - } else { - c = next; - } + } - /* Advance to next ring entry, exiting if we've reached - * the start of the ring or the ring has become empty - */ - } while (ring != NULL); + /* Finally, if we saved any fetches which were locked, put them back + * into the ring for next time + */ + ring = save_ring; } nserror fetch_file_register(void) -- cgit v1.2.3