From 184a12786053a2c60bb384f5e904162c78dfc75a Mon Sep 17 00:00:00 2001 From: obarthel Date: Sun, 4 Dec 2016 11:05:30 +0100 Subject: [PATCH] Added stdlib_decay_unused_slabs() --- library/GNUmakefile.68k | 3 ++ library/libc.gmk | 1 + library/stdlib_decay_unused_slabs.c | 75 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 library/stdlib_decay_unused_slabs.c diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 379881c..512d960 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -327,6 +327,7 @@ C_LIB = \ stdlib_exit.o \ stdlib_free.o \ stdlib_free_unused_slabs.o \ + stdlib_decay_unused_slabs.o \ stdlib_getdefstacksize.o \ stdlib_getenv.o \ stdlib_getmemstats.o \ @@ -1142,6 +1143,8 @@ $(LIBC_OBJS)/stdlib_get_slab_stats.o : stdlib_get_slab_stats.c stdlib_memory.h i $(LIBC_OBJS)/stdlib_free_unused_slabs.o : stdlib_free_unused_slabs.c stdlib_memory.h include/stdlib.h +$(LIBC_OBJS)/stdlib_decay_unused_slabs.o : stdlib_decay_unused_slabs.c stdlib_memory.h include/stdlib.h + $(LIBC_OBJS)/stdlib_get_slab_usage.o : stdlib_get_slab_usage.c stdlib_memory.h include/stdlib.h $(LIBC_OBJS)/stdlib_get_slab_allocations.o : stdlib_get_slab_allocations.c stdlib_memory.h include/stdlib.h diff --git a/library/libc.gmk b/library/libc.gmk index eb28adf..c0a5faa 100644 --- a/library/libc.gmk +++ b/library/libc.gmk @@ -212,6 +212,7 @@ C_LIB := \ stdlib_dosbase.o \ stdlib_exit.o \ stdlib_free.o \ + stdlib_decay_unused_slabs.o \ stdlib_free_unused_slabs.o \ stdlib_getdefstacksize.o \ stdlib_getenv.o \ diff --git a/library/stdlib_decay_unused_slabs.c b/library/stdlib_decay_unused_slabs.c new file mode 100644 index 0000000..384118b --- /dev/null +++ b/library/stdlib_decay_unused_slabs.c @@ -0,0 +1,75 @@ +/* + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2015 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEMORY_H +#include "stdlib_memory.h" +#endif /* _STDLIB_MEMORY_H */ + +/****************************************************************************/ + +/* Look at all currently unused slabs, decrementing the decay + * counter which prevents them from being reused. + */ +void +__decay_unused_slabs(void) +{ + if(__slab_data.sd_InUse) + { + struct MinNode * free_node; + struct MinNode * free_node_next; + struct SlabNode * sn; + + __memory_lock(); + + for(free_node = (struct MinNode *)__slab_data.sd_EmptySlabs.mlh_Head ; + free_node->mln_Succ != NULL ; + free_node = free_node_next) + { + free_node_next = (struct MinNode *)free_node->mln_Succ; + + /* free_node points to SlabNode.sn_EmptyLink, which + * directly follows the SlabNode.sn_MinNode. + */ + sn = (struct SlabNode *)&free_node[-1]; + + if(sn->sn_EmptyDecay > 0) + sn->sn_EmptyDecay--; + } + + __memory_unlock(); + } +}