summaryrefslogtreecommitdiff
path: root/frontends/amiga
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-11-27 15:31:18 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2016-11-27 15:31:18 +0000
commitc4b8857789e3f79a2ae0f7abe108999bf323b01a (patch)
tree6d2589211a2afd56169b46d54bb77e337bb69194 /frontends/amiga
parent20432237883a04677f30f1758979fa0a4b9111e3 (diff)
downloadnetsurf-c4b8857789e3f79a2ae0f7abe108999bf323b01a.tar.gz
netsurf-c4b8857789e3f79a2ae0f7abe108999bf323b01a.tar.bz2
Add low memory handler to purge unused slabs on OS3
TODO: find some way to purge NetSurf's memory cache safely from another process
Diffstat (limited to 'frontends/amiga')
-rw-r--r--frontends/amiga/gui.c10
-rwxr-xr-xfrontends/amiga/memory.c30
-rw-r--r--frontends/amiga/memory.h4
3 files changed, 43 insertions, 1 deletions
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index e5b5c597c..6dca47a05 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -5543,6 +5543,11 @@ int main(int argc, char** argv)
/* Open splash window */
Object *splash_window = ami_gui_splash_open();
+#ifndef __amigaos4__
+ /* OS3 low memory handler */
+ struct Interupt *memhandler = ami_memory_init();
+#endif
+
ami_object_init();
if (ami_open_resources() == false) { /* alloc message ports */
@@ -5743,6 +5748,11 @@ int main(int argc, char** argv)
ami_object_fini();
ami_bitmap_fini();
+#ifndef __amigaos4__
+ /* OS3 low memory handler */
+ ami_memory_fini(memhandler);
+#endif
+
LOG("Closing screen");
ami_gui_close_screen(scrn, locked_screen, FALSE);
if(nsscreentitle) FreeVec(nsscreentitle);
diff --git a/frontends/amiga/memory.c b/frontends/amiga/memory.c
index d86f73d74..abf849db6 100755
--- a/frontends/amiga/memory.c
+++ b/frontends/amiga/memory.c
@@ -17,8 +17,11 @@
*/
#ifndef __amigaos4__
+#include <proto/exec.h>
+#include <exec/interrupts.h>
#include <stdlib.h>
#include "amiga/memory.h"
+#include "amiga/os3support.h"
#include "utils/log.h"
ULONG __slab_max_size = 2048; /* Enable clib2's slab allocator */
@@ -60,5 +63,32 @@ void ami_memory_slab_dump(void)
{
__get_slab_usage(ami_memory_slab_callback);
}
+
+static ASM ULONG ami_memory_handler(REG(a0, struct MemHandlerData *mhd), REG(a1, void *userdata), REG(a6, struct ExecBase *execbase))
+{
+ __free_unused_slabs();
+
+ return MEM_ALL_DONE;
+}
+
+struct Interrupt *ami_memory_init(void)
+{
+ struct Interrupt *memhandler = malloc(sizeof(struct Interrupt));
+
+ memhandler->is_Node.ln_Pri = 1;
+ memhandler->is_Node.ln_Name = "NetSurf slab memory handler";
+ memhandler->is_Data = NULL;
+ memhandler->is_Code = (APTR)&ami_memory_handler;
+ AddMemHandler(memhandler);
+
+ return memhandler;
+}
+
+void ami_memory_fini(struct Interrupt *memhandler)
+{
+ RemMemHandler(memhandler);
+ free(memhandler);
+}
+
#endif
diff --git a/frontends/amiga/memory.h b/frontends/amiga/memory.h
index 3d9235062..a87a3ea97 100644
--- a/frontends/amiga/memory.h
+++ b/frontends/amiga/memory.h
@@ -57,9 +57,11 @@ void *ami_memory_clear_alloc(size_t size, UBYTE value);
#define ami_memory_itempool_free(p,i,s) FreePooled(p,i,s)
#endif
-/* clib2 slab allocator stats */
+/* clib2 slab allocator */
#ifndef __amigaos4__
void ami_memory_slab_dump(void);
+struct Interrupt *ami_memory_init(void);
+void ami_memory_fini(struct Interrupt *memhandler);
#endif
#endif //AMIGA_MEMORY_H