[project @ 2003-06-24 23:22:00 by bursa]
Change cache to use current content sizes. svn path=/import/netsurf/; revision=183
This commit is contained in:
parent
d60f376455
commit
9903df5654
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* $Id: cache.c,v 1.4 2003/06/17 19:24:20 bursa Exp $
|
||||
* $Id: cache.c,v 1.5 2003/06/24 23:22:00 bursa Exp $
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -27,21 +27,23 @@ void content_destroy(struct content *c);
|
|||
* internal structures and declarations
|
||||
*/
|
||||
|
||||
static void cache_shrink(void);
|
||||
static unsigned long cache_size(void);
|
||||
|
||||
struct cache_entry {
|
||||
struct content *content;
|
||||
time_t t;
|
||||
struct cache_entry *next, *prev;
|
||||
};
|
||||
|
||||
/* doubly-linked lists using a sentinel */
|
||||
/* TODO: replace with a structure which can be searched faster */
|
||||
static struct cache_entry inuse_list_sentinel = {0, 0, &inuse_list_sentinel, &inuse_list_sentinel};
|
||||
static struct cache_entry unused_list_sentinel = {0, 0, &unused_list_sentinel, &unused_list_sentinel};
|
||||
/* unused list is ordered from most recently to least recently used */
|
||||
static struct cache_entry inuse_list_sentinel = {0, &inuse_list_sentinel, &inuse_list_sentinel};
|
||||
static struct cache_entry unused_list_sentinel = {0, &unused_list_sentinel, &unused_list_sentinel};
|
||||
static struct cache_entry *inuse_list = &inuse_list_sentinel;
|
||||
static struct cache_entry *unused_list = &unused_list_sentinel;
|
||||
|
||||
static unsigned long max_size = 1024*1024; /* TODO: make this configurable */
|
||||
static unsigned long current_size = 0;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -110,19 +112,7 @@ void cache_put(struct content * content)
|
|||
struct cache_entry * e;
|
||||
LOG(("content %p, url '%s', size %lu", content, content->url, content->size));
|
||||
|
||||
/* TODO: contents will grow in size as they load */
|
||||
current_size += content->size;
|
||||
/* clear old data from the usused_list until the size drops below max_size */
|
||||
while (max_size < current_size && unused_list->next != unused_list) {
|
||||
e = unused_list->next;
|
||||
LOG(("size %lu, removing %p '%s'", current_size, e->content, e->content->url));
|
||||
/* TODO: move to disc cache */
|
||||
current_size -= e->content->size;
|
||||
content_destroy(e->content);
|
||||
unused_list->next = e->next;
|
||||
e->next->prev = e->prev;
|
||||
xfree(e);
|
||||
}
|
||||
cache_shrink();
|
||||
|
||||
/* add the new content to the inuse_list */
|
||||
e = xcalloc(1, sizeof(struct cache_entry));
|
||||
|
@ -146,32 +136,66 @@ void cache_freeable(struct content * content)
|
|||
assert(e != 0);
|
||||
LOG(("content %p, url '%s'", content, content->url));
|
||||
|
||||
/* move to unused_list or destroy if insufficient space */
|
||||
e->t = time(0);
|
||||
/* move to unused_list */
|
||||
e->prev->next = e->next;
|
||||
e->next->prev = e->prev;
|
||||
if (max_size < current_size) {
|
||||
LOG(("size %lu, removing", current_size));
|
||||
/* TODO: move to disc cache */
|
||||
current_size -= e->content->size;
|
||||
content_destroy(e->content);
|
||||
xfree(e);
|
||||
} else {
|
||||
LOG(("size %lu, moving to unused_list", current_size));
|
||||
e->prev = unused_list->prev;
|
||||
e->next = unused_list;
|
||||
unused_list->prev->next = e;
|
||||
unused_list->prev = e;
|
||||
}
|
||||
e->prev = unused_list;
|
||||
e->next = unused_list->next;
|
||||
unused_list->next->prev = e;
|
||||
unused_list->next = e;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cache_destroy -- remove a content immediately
|
||||
*/
|
||||
|
||||
void cache_destroy(struct content * content)
|
||||
{
|
||||
struct cache_entry * e = content->cache;
|
||||
e->prev->next = e->next;
|
||||
e->next->prev = e->prev;
|
||||
current_size -= content->size;
|
||||
xfree(e);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cache_shrink -- attempt to reduce cache size below max_size
|
||||
*/
|
||||
|
||||
void cache_shrink(void)
|
||||
{
|
||||
struct cache_entry * e;
|
||||
unsigned long size = cache_size();
|
||||
|
||||
/* clear old data from the usused_list until the size drops below max_size */
|
||||
while (max_size < size && unused_list->next != unused_list) {
|
||||
e = unused_list->prev;
|
||||
LOG(("size %lu, removing %p '%s'", size, e->content, e->content->url));
|
||||
/* TODO: move to disc cache */
|
||||
size -= e->content->size;
|
||||
content_destroy(e->content);
|
||||
unused_list->prev = e->prev;
|
||||
e->prev->next = unused_list;
|
||||
xfree(e);
|
||||
}
|
||||
LOG(("size %lu", size));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cache_size -- current size of the cache
|
||||
*/
|
||||
|
||||
unsigned long cache_size(void)
|
||||
{
|
||||
struct cache_entry * e;
|
||||
unsigned long size = 0;
|
||||
for (e = inuse_list->next; e != inuse_list; e = e->next)
|
||||
size += e->content->size;
|
||||
for (e = unused_list->next; e != unused_list; e = e->next)
|
||||
size += e->content->size;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,15 +205,15 @@ void cache_destroy(struct content * content)
|
|||
|
||||
void cache_dump(void) {
|
||||
struct cache_entry * e;
|
||||
LOG(("size %lu", current_size));
|
||||
LOG(("size %lu", cache_size()));
|
||||
LOG(("inuse_list:"));
|
||||
for (e = inuse_list->next; e != inuse_list; e = e->next)
|
||||
LOG((" content %p, size %lu, url '%s'", e->content,
|
||||
e->content->size, e->content->url));
|
||||
LOG(("unused_list (time now %lu):", time(0)));
|
||||
for (e = unused_list->next; e != unused_list; e = e->next)
|
||||
LOG((" content %p, size %lu, url '%s', t %lu", e->content,
|
||||
e->content->size, e->content->url, e->t));
|
||||
LOG((" content %p, size %lu, url '%s'", e->content,
|
||||
e->content->size, e->content->url));
|
||||
LOG(("end"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/**
|
||||
* $Id: content.c,v 1.11 2003/06/17 19:24:20 bursa Exp $
|
||||
/*
|
||||
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
||||
* Licensed under the GNU General Public License,
|
||||
* http://www.opensource.org/licenses/gpl-license
|
||||
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* $Id: fetch.c,v 1.10 2003/06/17 19:24:20 bursa Exp $
|
||||
* $Id: fetch.c,v 1.11 2003/06/24 23:22:00 bursa Exp $
|
||||
*
|
||||
* This module handles fetching of data from any url.
|
||||
*
|
||||
|
@ -21,6 +21,9 @@
|
|||
#include "netsurf/utils/utils.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/desktop/options.h"
|
||||
#ifdef riscos
|
||||
#include "netsurf/desktop/gui.h"
|
||||
#endif
|
||||
|
||||
struct fetch
|
||||
{
|
||||
|
@ -42,6 +45,7 @@ struct fetch
|
|||
};
|
||||
|
||||
static const char * const user_agent = "NetSurf";
|
||||
static char * ca_bundle;
|
||||
static CURLM * curl_multi;
|
||||
static struct fetch *fetch_list = 0;
|
||||
|
||||
|
@ -64,6 +68,12 @@ void fetch_init(void)
|
|||
curl_multi = curl_multi_init();
|
||||
if (curl_multi == 0)
|
||||
die("curl_multi_init failed");
|
||||
|
||||
#ifdef riscos
|
||||
ca_bundle = xcalloc(strlen(NETSURF_DIR) + 100, 1);
|
||||
sprintf(ca_bundle, "%s.Resources.ca-bundle", NETSURF_DIR);
|
||||
LOG(("ca_bundle '%s'", ca_bundle));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -170,6 +180,10 @@ struct fetch * fetch_start(char *url, char *referer,
|
|||
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_REFERER, referer);
|
||||
assert(code == CURLE_OK);
|
||||
}
|
||||
#ifdef riscos
|
||||
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_CAINFO, ca_bundle);
|
||||
assert(code == CURLE_OK);
|
||||
#endif
|
||||
|
||||
/* custom request headers */
|
||||
fetch->headers = 0;
|
||||
|
|
6
makefile
6
makefile
|
@ -1,4 +1,4 @@
|
|||
# $Id: makefile,v 1.35 2003/06/21 13:18:00 bursa Exp $
|
||||
# $Id: makefile,v 1.36 2003/06/24 23:22:00 bursa Exp $
|
||||
|
||||
CC = riscos-gcc
|
||||
CC_DEBUG = gcc
|
||||
|
@ -29,7 +29,9 @@ LDFLAGS = \
|
|||
/usr/local/riscoslibs/OSLib/OSLib32.ro \
|
||||
/usr/local/riscoslibs/curl/libcurl.ro \
|
||||
/usr/local/riscoslibs/libpng/libpng.ro \
|
||||
/usr/local/riscoslibs/zlib/libz.ro
|
||||
/usr/local/riscoslibs/zlib/libz.ro \
|
||||
/usr/local/riscoslibs/openssl/lib/libssl.a \
|
||||
/usr/local/riscoslibs/openssl/lib/libcrypto.a
|
||||
LDFLAGS_DEBUG = -L/usr/lib -lxml2 -lz -lm -lcurl -lssl -lcrypto -ldl
|
||||
|
||||
OBJDIR = $(shell $(CC) -dumpmachine)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* $Id: gui.c,v 1.33 2003/06/17 19:24:21 bursa Exp $
|
||||
* $Id: gui.c,v 1.34 2003/06/24 23:22:00 bursa Exp $
|
||||
*/
|
||||
|
||||
#include "netsurf/desktop/options.h"
|
||||
|
@ -23,6 +23,8 @@
|
|||
|
||||
const char *__dynamic_da_name = "NetSurf";
|
||||
|
||||
char *NETSURF_DIR;
|
||||
|
||||
int gadget_subtract_x;
|
||||
int gadget_subtract_y;
|
||||
#define browser_menu_flags (wimp_ICON_TEXT | wimp_ICON_FILLED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))
|
||||
|
@ -1109,6 +1111,8 @@ void gui_init(int argc, char** argv)
|
|||
os_error *e;
|
||||
fileswitch_object_type *ot;
|
||||
|
||||
NETSURF_DIR = getenv("NetSurf$Dir");
|
||||
|
||||
/* __riscosify_control = __RISCOSIFY_NO_PROCESS; */
|
||||
|
||||
task_handle = wimp_initialise(wimp_VERSION_RO38, task_name, (wimp_message_list*) &task_messages, &version);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* $Id: gui.h,v 1.6 2003/04/15 18:07:25 bursa Exp $
|
||||
* $Id: gui.h,v 1.7 2003/06/24 23:22:00 bursa Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETSURF_RISCOS_GUI_H_
|
||||
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "oslib/wimp.h"
|
||||
|
||||
extern char *NETSURF_DIR;
|
||||
|
||||
struct ro_gui_window;
|
||||
typedef struct ro_gui_window gui_window;
|
||||
|
||||
|
|
Loading…
Reference in New Issue