summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2011-03-13 18:26:46 +0000
committerDaniel Silverstone <dsilvers@netsurf-browser.org>2011-03-13 18:26:46 +0000
commit93e9bfe3232fbcb3531acf07a870ed404c526f27 (patch)
tree7835b3cc4ac66d21fc64460c5f11f6e62760a042
parentc615507e150592895980608d00601beed16d28b9 (diff)
downloadnetsurf-93e9bfe3232fbcb3531acf07a870ed404c526f27.tar.gz
netsurf-93e9bfe3232fbcb3531acf07a870ed404c526f27.tar.bz2
Shunt the schedule function definitions to desktop/schedule.h. Shunt the hlcache/llcache to using schedule to get their cleanups run.
svn path=/trunk/netsurf/; revision=12029
-rwxr-xr-xamiga/schedule.c2
-rwxr-xr-xatari/schedule.c2
-rw-r--r--content/fetchers/curl.c1
-rw-r--r--content/hlcache.c52
-rw-r--r--content/hlcache.h9
-rw-r--r--content/llcache.c25
-rw-r--r--content/llcache.h11
-rw-r--r--desktop/browser.c1
-rw-r--r--desktop/browser.h6
-rw-r--r--desktop/cookies.c1
-rw-r--r--desktop/netsurf.c5
-rw-r--r--desktop/schedule.h32
-rw-r--r--framebuffer/gui.c1
-rw-r--r--framebuffer/schedule.c3
-rw-r--r--gtk/schedule.c2
-rw-r--r--image/gif.c2
-rw-r--r--image/mng.c2
-rw-r--r--monkey/schedule.c2
-rw-r--r--render/html.c1
-rw-r--r--riscos/schedule.c1
-rw-r--r--windows/schedule.c2
21 files changed, 102 insertions, 61 deletions
diff --git a/amiga/schedule.c b/amiga/schedule.c
index 0be34bbe8..d5aa27e6f 100755
--- a/amiga/schedule.c
+++ b/amiga/schedule.c
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "amiga/os3support.h"
#include "amiga/schedule.h"
diff --git a/atari/schedule.c b/atari/schedule.c
index e72e1bcbe..3556de768 100755
--- a/atari/schedule.c
+++ b/atari/schedule.c
@@ -19,7 +19,7 @@
#include <sys/time.h>
#include <time.h>
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "atari/schedule.h"
#include "utils/log.h"
diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c
index 895dc4256..8140aa64e 100644
--- a/content/fetchers/curl.c
+++ b/content/fetchers/curl.c
@@ -44,6 +44,7 @@
#include "content/urldb.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
+#include "desktop/schedule.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"
diff --git a/content/hlcache.c b/content/hlcache.c
index b31b0d4d8..08848e0aa 100644
--- a/content/hlcache.c
+++ b/content/hlcache.c
@@ -26,6 +26,7 @@
#include "content/content.h"
#include "content/hlcache.h"
+#include "desktop/schedule.h"
#include "utils/http.h"
#include "utils/log.h"
#include "utils/messages.h"
@@ -74,7 +75,8 @@ static hlcache_entry *hlcache_content_list;
/** Ring of retrieval contexts */
static hlcache_retrieval_ctx *hlcache_retrieval_ctx_ring;
-static void hlcache_clean(void);
+static void hlcache_clean(void *ignored);
+
static nserror hlcache_llcache_callback(llcache_handle *handle,
const llcache_event *event, void *pw);
static bool hlcache_type_is_acceptable(llcache_handle *llcache,
@@ -88,13 +90,31 @@ static void hlcache_content_callback(struct content *c,
* Public API *
******************************************************************************/
+nserror
+hlcache_initialise(llcache_query_callback cb, void *pw)
+{
+ nserror ret = llcache_initialise(cb, pw);
+
+ if (ret != NSERROR_OK)
+ return ret;
+
+ /* Schedule the cache cleanup for 5 seconds time */
+ schedule(500, hlcache_clean, NULL);
+
+ return NSERROR_OK;
+}
+
+
/* See hlcache.h for documentation */
void hlcache_finalise(void)
{
uint32_t num_contents, prev_contents;
hlcache_entry *entry;
hlcache_retrieval_ctx *ctx, *next;
-
+
+ /* Remove the hlcache_clean schedule */
+ schedule_remove(hlcache_clean, NULL);
+
/* Obtain initial count of contents remaining */
for (num_contents = 0, entry = hlcache_content_list;
entry != NULL; entry = entry->next) {
@@ -107,7 +127,7 @@ void hlcache_finalise(void)
do {
prev_contents = num_contents;
- hlcache_clean();
+ hlcache_clean(NULL);
for (num_contents = 0, entry = hlcache_content_list;
entry != NULL; entry = entry->next) {
@@ -123,7 +143,7 @@ void hlcache_finalise(void)
LOG((" %p : %s (%d users)", entry,
content_get_url(&entry_handle), content_count_users(entry->content)));
} else {
- LOG((" %p", entry));
+ LOG((" %p", entry));
}
}
@@ -155,23 +175,9 @@ void hlcache_finalise(void)
/* See hlcache.h for documentation */
nserror hlcache_poll(void)
{
- static uint32_t last_clean_time;
- uint32_t now;
llcache_poll();
- /* Only attempt to clean the cache every 5 seconds */
-#define HLCACHE_CLEAN_INTERVAL_CS (500)
- now = wallclock();
-
- if (now > last_clean_time + HLCACHE_CLEAN_INTERVAL_CS) {
- /* Give the cache a clean */
- hlcache_clean();
-
- last_clean_time = now;
- }
-#undef HLCACHE_CLEAN_INTERVAL_CS
-
return NSERROR_OK;
}
@@ -368,7 +374,7 @@ nserror hlcache_handle_replace_callback(hlcache_handle *handle,
/**
* Attempt to clean the cache
*/
-void hlcache_clean(void)
+void hlcache_clean(void *ignored)
{
hlcache_entry *entry, *next;
@@ -407,6 +413,12 @@ void hlcache_clean(void)
/* Destroy entry */
free(entry);
}
+
+ /* Attempt to clean the llcache */
+ llcache_clean();
+
+ /* Re-schedule ourselves for 5 seconds time */
+ schedule(500, hlcache_clean, NULL);
}
/**
@@ -447,7 +459,7 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
llcache_handle_abort(handle);
llcache_handle_release(handle);
- free((char *) ctx->child.charset);
+ free((char *) ctx->child.charset);
free(ctx);
return error;
}
diff --git a/content/hlcache.h b/content/hlcache.h
index 5ed37203d..6738fea53 100644
--- a/content/hlcache.h
+++ b/content/hlcache.h
@@ -64,6 +64,15 @@ enum hlcache_retrieve_flag {
};
/**
+ * Initialise the high-level cache, preparing the llcache also.
+ *
+ * \param cb Query handler for llcache
+ * \param pw Pointer to llcache query handler data
+ * \return NSERROR_OK on success, appropriate error otherwise.
+ */
+nserror hlcache_initialise(llcache_query_callback cb, void *pw);
+
+/**
* Finalise the high-level cache, destroying any remaining contents
*/
void hlcache_finalise(void);
diff --git a/content/llcache.c b/content/llcache.c
index 1deb8cae9..893c505fb 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -193,8 +193,6 @@ static nserror llcache_object_notify_users(llcache_object *object);
static nserror llcache_object_snapshot(llcache_object *object,
llcache_object **snapshot);
-static nserror llcache_clean(void);
-
static nserror llcache_post_data_clone(const llcache_post_data *orig,
llcache_post_data **clone);
@@ -307,8 +305,6 @@ void llcache_finalise(void)
/* See llcache.h for documentation */
nserror llcache_poll(void)
{
- static uint32_t last_clean_time;
- uint32_t now;
llcache_object *object;
fetch_poll();
@@ -324,18 +320,6 @@ nserror llcache_poll(void)
llcache_object_notify_users(object);
}
- /* Only attempt to clean the cache every 5 seconds */
-#define LLCACHE_CLEAN_INTERVAL_CS (500)
- now = wallclock();
-
- if (now > last_clean_time + LLCACHE_CLEAN_INTERVAL_CS) {
- /* Attempt to clean the cache */
- llcache_clean();
-
- last_clean_time = now;
- }
-#undef LLCACHE_CLEAN_INTERVAL_CS
-
return NSERROR_OK;
}
@@ -1611,10 +1595,8 @@ nserror llcache_object_snapshot(llcache_object *object,
/**
* Attempt to clean the cache
- *
- * \return NSERROR_OK.
*/
-nserror llcache_clean(void)
+void llcache_clean(void)
{
llcache_object *object, *next;
uint32_t llcache_size = 0;
@@ -1697,7 +1679,6 @@ nserror llcache_clean(void)
LOG(("Size: %u", llcache_size));
#endif
- return NSERROR_OK;
}
/**
@@ -2241,8 +2222,8 @@ nserror llcache_fetch_split_header(const char *data, size_t len, char **name,
* \return NSERROR_OK on success, appropriate error otherwise
*
* \note This function also has the side-effect of updating
- * the cache control data for the object if an interesting
- * header is encountered
+ * the cache control data for the object if an interesting
+ * header is encountered
*/
nserror llcache_fetch_parse_header(llcache_object *object, const char *data,
size_t len, char **name, char **value)
diff --git a/content/llcache.h b/content/llcache.h
index d7958b056..215e6cc1a 100644
--- a/content/llcache.h
+++ b/content/llcache.h
@@ -166,15 +166,20 @@ nserror llcache_initialise(llcache_query_callback cb, void *pw);
void llcache_finalise(void);
/**
- * Cause the low-level cache to emit any pending notifications
- * and attempt to clean the cache. No guarantee is made about
- * what, if any, cache cleaning will occur.
+ * Cause the low-level cache to emit any pending notifications.
*
* \return NSERROR_OK on success, appropriate error otherwise.
*/
nserror llcache_poll(void);
/**
+ * Cause the low-level cache to attempt to perform cleanup. No
+ * guarantees are made as to whether or not cleanups will take
+ * place and what, if any, space savings will be made.
+ */
+void llcache_clean(void);
+
+/**
* Retrieve a handle for a low-level cache object
*
* \param url URL of the object to fetch
diff --git a/desktop/browser.c b/desktop/browser.c
index ecf43b61b..63b61de16 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -51,6 +51,7 @@
#include "desktop/knockout.h"
#include "desktop/options.h"
#include "desktop/selection.h"
+#include "desktop/schedule.h"
#include "desktop/textinput.h"
#include "desktop/plotters.h"
diff --git a/desktop/browser.h b/desktop/browser.h
index 717c032c2..a9cba2ee7 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -291,12 +291,6 @@ void global_history_add(const char *url);
void global_history_add_recent(const char *url);
char **global_history_get_recent(int *count);
-/* In platform specific schedule.c. */
-typedef void (*schedule_callback_fn)(void *p);
-
-void schedule(int t, schedule_callback_fn callback, void *p);
-void schedule_remove(schedule_callback_fn callback, void *p);
-
/* In platform specific theme_install.c. */
#ifdef WITH_THEME_INSTALL
void theme_install_start(struct hlcache_handle *c);
diff --git a/desktop/cookies.c b/desktop/cookies.c
index a49a8db9f..4862b690e 100644
--- a/desktop/cookies.c
+++ b/desktop/cookies.c
@@ -32,6 +32,7 @@
#include "content/urldb.h"
#include "desktop/cookies.h"
#include "desktop/options.h"
+#include "desktop/schedule.h"
#include "desktop/tree.h"
#include "utils/messages.h"
#include "utils/log.h"
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index 789868ec3..3edbae8d5 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -145,8 +145,9 @@ nserror netsurf_init(int *pargc,
setlocale(LC_ALL, "C");
fetch_init();
-
- llcache_initialise(netsurf_llcache_query_handler, NULL);
+
+ /* Initialise the hlcache and allow it to init the llcache for us */
+ hlcache_initialise(netsurf_llcache_query_handler, NULL);
/* Initialize system colours */
gui_system_colour_init();
diff --git a/desktop/schedule.h b/desktop/schedule.h
new file mode 100644
index 000000000..8d5aa1e90
--- /dev/null
+++ b/desktop/schedule.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 Daniel Silverstone <dsilvers@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** \file
+ * Job scheduler (interface).
+ */
+
+#ifndef _NETSURF_DESKTOP_SCHEDULE_H_
+#define _NETSURF_DESKTOP_SCHEDULE_H_
+
+/* In platform specific schedule.c. */
+typedef void (*schedule_callback_fn)(void *p);
+
+void schedule(int t, schedule_callback_fn callback, void *p);
+void schedule_remove(schedule_callback_fn callback, void *p);
+
+#endif
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index a906b650c..aa390666d 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -37,6 +37,7 @@
#include "desktop/netsurf.h"
#include "desktop/options.h"
#include "desktop/shape.h"
+#include "desktop/schedule.h"
#include "utils/resource.h"
#include "utils/log.h"
#include "utils/url.h"
diff --git a/framebuffer/schedule.c b/framebuffer/schedule.c
index 132dd8b0d..63ef19c6c 100644
--- a/framebuffer/schedule.c
+++ b/framebuffer/schedule.c
@@ -18,8 +18,9 @@
#include <sys/time.h>
#include <time.h>
+#include <stdlib.h>
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "framebuffer/schedule.h"
#include "utils/log.h"
diff --git a/gtk/schedule.c b/gtk/schedule.c
index 9491ccb67..8cf8563b1 100644
--- a/gtk/schedule.c
+++ b/gtk/schedule.c
@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <stdbool.h>
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "gtk/schedule.h"
#ifdef DEBUG_GTK_SCHEDULE
diff --git a/image/gif.c b/image/gif.c
index 7b8c2ec0c..1863a2fef 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -38,7 +38,7 @@
#include <libnsgif.h>
#include "utils/config.h"
#include "content/content_protected.h"
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "desktop/options.h"
#include "desktop/plotters.h"
#include "image/bitmap.h"
diff --git a/image/mng.c b/image/mng.c
index 1674dd033..a4648e5a3 100644
--- a/image/mng.c
+++ b/image/mng.c
@@ -33,7 +33,7 @@
#include <sys/time.h>
#include <time.h>
#include <libmng.h>
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "desktop/options.h"
#include "desktop/plotters.h"
#include "image/bitmap.h"
diff --git a/monkey/schedule.c b/monkey/schedule.c
index 372a304bf..78051994b 100644
--- a/monkey/schedule.c
+++ b/monkey/schedule.c
@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <stdbool.h>
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "gtk/schedule.h"
#undef DEBUG_MONKEY_SCHEDULE
diff --git a/render/html.c b/render/html.c
index 469d507a8..07232fca5 100644
--- a/render/html.c
+++ b/render/html.c
@@ -34,6 +34,7 @@
#include "desktop/browser.h"
#include "desktop/gui.h"
#include "desktop/options.h"
+#include "desktop/schedule.h"
#include "image/bitmap.h"
#include "render/box.h"
#include "render/favicon.h"
diff --git a/riscos/schedule.c b/riscos/schedule.c
index d0d27401c..fb8dce03a 100644
--- a/riscos/schedule.c
+++ b/riscos/schedule.c
@@ -27,6 +27,7 @@
#include "oslib/os.h"
#include "riscos/gui.h"
#include "utils/log.h"
+#include "desktop/schedule.h"
/** Entry in the queue of scheduled callbacks. */
diff --git a/windows/schedule.c b/windows/schedule.c
index f363d476a..559e0a395 100644
--- a/windows/schedule.c
+++ b/windows/schedule.c
@@ -19,7 +19,7 @@
#include <sys/time.h>
#include <time.h>
-#include "desktop/browser.h"
+#include "desktop/schedule.h"
#include "framebuffer/schedule.h"
#include "utils/log.h"