From c4b8857789e3f79a2ae0f7abe108999bf323b01a Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 27 Nov 2016 15:31:18 +0000 Subject: Add low memory handler to purge unused slabs on OS3 TODO: find some way to purge NetSurf's memory cache safely from another process --- frontends/amiga/gui.c | 10 ++++++++++ frontends/amiga/memory.c | 30 ++++++++++++++++++++++++++++++ frontends/amiga/memory.h | 4 +++- 3 files changed, 43 insertions(+), 1 deletion(-) 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 +#include #include #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 -- cgit v1.2.3