Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/bb5d72410bf9a3a997ade1e8760b8f240d32af0d
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/bb5d72410bf9a3a997ade1e8760b8f240d32af0d
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/bb5d72410bf9a3a997ade1e8760b8f240d32af0d

The branch, master has been updated
       via  bb5d72410bf9a3a997ade1e8760b8f240d32af0d (commit)
      from  a47270c93eaa7bb76638c4c6dbef23359531651c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=bb5d72410bf9a3a997ade1e8760b8f240d32af0d
commit bb5d72410bf9a3a997ade1e8760b8f240d32af0d
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    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 <[email protected]>

diff --git a/content/fetchers/about.c b/content/fetchers/about.c
index dda8fc8..0e85eff 100644
--- a/content/fetchers/about.c
+++ b/content/fetchers/about.c
@@ -1580,7 +1580,6 @@ static void fetch_about_free(void *ctx)
 {
        struct fetch_about_context *c = ctx;
        nsurl_unref(c->url);
-       RING_REMOVE(ring, c);
        free(ctx);
 }
 
@@ -1614,14 +1613,14 @@ static void fetch_about_abort(void *ctx)
  */
 static void fetch_about_poll(lwc_string *scheme)
 {
-       struct fetch_about_context *c, *next;
-       bool was_last_item = false;
-
-       if (ring == NULL) return;
+       struct fetch_about_context *c, *save_ring = NULL;
 
        /* Iterate over ring, processing each pending fetch */
-       c = ring;
-       do {
+       while (ring != NULL) {
+               /* Take the first entry from the ring */
+               c = ring;
+               RING_REMOVE(ring, c);
+
                /* 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,
@@ -1629,7 +1628,7 @@ static void fetch_about_poll(lwc_string *scheme)
                 * again.
                 */
                if (c->locked == true) {
-                       next = c->r_next;
+                       RING_INSERT(save_ring, c);
                        continue;
                }
 
@@ -1639,32 +1638,15 @@ static void fetch_about_poll(lwc_string *scheme)
                        c->handler(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;
 }
 
 
diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 8316d15..c7de14c 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -135,7 +135,6 @@ static void fetch_data_free(void *ctx)
        nsurl_unref(c->url);
        free(c->data);
        free(c->mimetype);
-       RING_REMOVE(ring, c);
        free(ctx);
 }
 
@@ -245,14 +244,14 @@ static bool fetch_data_process(struct fetch_data_context 
*c)
 static void fetch_data_poll(lwc_string *scheme)
 {
        fetch_msg msg;
-       struct fetch_data_context *c, *next;
-       bool was_last_item = false;
-       
-       if (ring == NULL) return;
+       struct fetch_data_context *c, *save_ring = NULL;
        
        /* Iterate over ring, processing each pending fetch */
-       c = ring;
-       do {
+       while (ring != NULL) {
+               /* Take the first entry from the ring */
+               c = ring;
+               RING_REMOVE(ring, c);
+
                /* 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,
@@ -260,7 +259,7 @@ static void fetch_data_poll(lwc_string *scheme)
                 * again.
                 */
                if (c->locked == true) {
-                       next = c->r_next;
+                       RING_INSERT(save_ring, c);
                        continue;
                }
 
@@ -311,32 +310,15 @@ static void fetch_data_poll(lwc_string *scheme)
                        assert(c->locked == false);
                }
 
-               /* 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->parent_fetch);
                fetch_free(c->parent_fetch);
+       }
 
-               /* 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_data_register(void)
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index ede001f..bf2cc32 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)
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index c17ffd9..c8176f3 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -406,7 +406,6 @@ static void fetch_resource_free(void *ctx)
        struct fetch_resource_context *c = ctx;
        if (c->url != NULL)
                nsurl_unref(c->url);
-       RING_REMOVE(ring, c);
        free(ctx);
 }
 
@@ -432,14 +431,13 @@ static void fetch_resource_abort(void *ctx)
 /** callback to poll for additional resource fetch contents */
 static void fetch_resource_poll(lwc_string *scheme)
 {
-       struct fetch_resource_context *c, *next;
-       bool was_last_item = false;
+       struct fetch_resource_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,
@@ -447,7 +445,7 @@ static void fetch_resource_poll(lwc_string *scheme)
                 * again.
                 */
                if (c->locked == true) {
-                       next = c->r_next;
+                       RING_INSERT(save_ring, c);
                        continue;
                }
 
@@ -457,32 +455,15 @@ static void fetch_resource_poll(lwc_string *scheme)
                        c->handler(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_resource_register(void)


-----------------------------------------------------------------------

Summary of changes:
 content/fetchers/about.c    |   44 +++++++++++++------------------------------
 content/fetchers/data.c     |   44 +++++++++++++------------------------------
 content/fetchers/file.c     |   42 ++++++++++++-----------------------------
 content/fetchers/resource.c |   43 ++++++++++++------------------------------
 4 files changed, 50 insertions(+), 123 deletions(-)

diff --git a/content/fetchers/about.c b/content/fetchers/about.c
index dda8fc8..0e85eff 100644
--- a/content/fetchers/about.c
+++ b/content/fetchers/about.c
@@ -1580,7 +1580,6 @@ static void fetch_about_free(void *ctx)
 {
        struct fetch_about_context *c = ctx;
        nsurl_unref(c->url);
-       RING_REMOVE(ring, c);
        free(ctx);
 }
 
@@ -1614,14 +1613,14 @@ static void fetch_about_abort(void *ctx)
  */
 static void fetch_about_poll(lwc_string *scheme)
 {
-       struct fetch_about_context *c, *next;
-       bool was_last_item = false;
-
-       if (ring == NULL) return;
+       struct fetch_about_context *c, *save_ring = NULL;
 
        /* Iterate over ring, processing each pending fetch */
-       c = ring;
-       do {
+       while (ring != NULL) {
+               /* Take the first entry from the ring */
+               c = ring;
+               RING_REMOVE(ring, c);
+
                /* 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,
@@ -1629,7 +1628,7 @@ static void fetch_about_poll(lwc_string *scheme)
                 * again.
                 */
                if (c->locked == true) {
-                       next = c->r_next;
+                       RING_INSERT(save_ring, c);
                        continue;
                }
 
@@ -1639,32 +1638,15 @@ static void fetch_about_poll(lwc_string *scheme)
                        c->handler(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;
 }
 
 
diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 8316d15..c7de14c 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -135,7 +135,6 @@ static void fetch_data_free(void *ctx)
        nsurl_unref(c->url);
        free(c->data);
        free(c->mimetype);
-       RING_REMOVE(ring, c);
        free(ctx);
 }
 
@@ -245,14 +244,14 @@ static bool fetch_data_process(struct fetch_data_context 
*c)
 static void fetch_data_poll(lwc_string *scheme)
 {
        fetch_msg msg;
-       struct fetch_data_context *c, *next;
-       bool was_last_item = false;
-       
-       if (ring == NULL) return;
+       struct fetch_data_context *c, *save_ring = NULL;
        
        /* Iterate over ring, processing each pending fetch */
-       c = ring;
-       do {
+       while (ring != NULL) {
+               /* Take the first entry from the ring */
+               c = ring;
+               RING_REMOVE(ring, c);
+
                /* 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,
@@ -260,7 +259,7 @@ static void fetch_data_poll(lwc_string *scheme)
                 * again.
                 */
                if (c->locked == true) {
-                       next = c->r_next;
+                       RING_INSERT(save_ring, c);
                        continue;
                }
 
@@ -311,32 +310,15 @@ static void fetch_data_poll(lwc_string *scheme)
                        assert(c->locked == false);
                }
 
-               /* 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->parent_fetch);
                fetch_free(c->parent_fetch);
+       }
 
-               /* 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_data_register(void)
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index ede001f..bf2cc32 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)
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index c17ffd9..c8176f3 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -406,7 +406,6 @@ static void fetch_resource_free(void *ctx)
        struct fetch_resource_context *c = ctx;
        if (c->url != NULL)
                nsurl_unref(c->url);
-       RING_REMOVE(ring, c);
        free(ctx);
 }
 
@@ -432,14 +431,13 @@ static void fetch_resource_abort(void *ctx)
 /** callback to poll for additional resource fetch contents */
 static void fetch_resource_poll(lwc_string *scheme)
 {
-       struct fetch_resource_context *c, *next;
-       bool was_last_item = false;
+       struct fetch_resource_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,
@@ -447,7 +445,7 @@ static void fetch_resource_poll(lwc_string *scheme)
                 * again.
                 */
                if (c->locked == true) {
-                       next = c->r_next;
+                       RING_INSERT(save_ring, c);
                        continue;
                }
 
@@ -457,32 +455,15 @@ static void fetch_resource_poll(lwc_string *scheme)
                        c->handler(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_resource_register(void)


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to