From: Gunnar Beutner Date: Tue, 30 Jul 2013 16:40:47 +0000 (+0200) Subject: Use nsmalloc/nsfree for chanstats. X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/e5c21551815810484710b5d7f35a975251ff87a9 Use nsmalloc/nsfree for chanstats. --- diff --git a/chanstats/chanstats.c b/chanstats/chanstats.c index 6f072878..b6c6402a 100644 --- a/chanstats/chanstats.c +++ b/chanstats/chanstats.c @@ -54,7 +54,6 @@ void _init() { Error("chanstats",ERR_ERROR,"Couldn't register channel extension"); failedinit=1; } else { - initchanstatsalloc(); lastday=(getnettime()/(24*3600)); uponehour=0; sampleindex=-1; diff --git a/chanstats/chanstats.h b/chanstats/chanstats.h index e642926b..f132bb2c 100644 --- a/chanstats/chanstats.h +++ b/chanstats/chanstats.h @@ -45,7 +45,6 @@ chanstats *findchanstatsifexists(const char *channame); /* chanstatsalloc.c */ void cstsfreeall(); -void initchanstatsalloc(); chanstats *getchanstats(); void freechanstats(chanstats *csp); diff --git a/chanstats/chanstatsalloc.c b/chanstats/chanstatsalloc.c index 2a8959b7..1506a301 100644 --- a/chanstats/chanstatsalloc.c +++ b/chanstats/chanstatsalloc.c @@ -1,66 +1,16 @@ /* Allocators for chanstats */ #include "chanstats.h" - -#include - -#define ALLOCUNIT 100 - -static void *malloclist; -static chanstats *freecs; - -void *cstsmalloc(size_t size) { - void **mem; - - /* Get the memory we want, with an extra four bytes for our pointer */ - mem=(void **)malloc(size+sizeof(void *)); - - /* Set the first word to point at the last chunk we got */ - *mem=malloclist; - - /* Now set the "last chunk" pointer to the address of this one */ - malloclist=(void *)mem; - - /* Return the rest of the memory to the caller */ - return (void *)(mem+1); -} +#include "../core/nsmalloc.h" void cstsfreeall() { - void *vp,**vp2; - - vp=malloclist; - - while (vp!=NULL) { - vp2=(void **)vp; - vp=*vp2; - free((void *)vp2); - } -} - -void initchanstatsalloc() { - malloclist=NULL; - freecs=NULL; + nsfreeall(POOL_CHANSTATS); } chanstats *getchanstats() { - chanstats *csp; - int i; - - if (freecs==NULL) { - freecs=(chanstats *)cstsmalloc(ALLOCUNIT*sizeof(chanstats)); - for(i=0;i<(ALLOCUNIT-1);i++) { - freecs[i].index=(chanindex *)&(freecs[i+1]); - } - freecs[ALLOCUNIT-1].index=NULL; - } - - csp=freecs; - freecs=(chanstats *)csp->index; - - return csp; + return nsmalloc(POOL_CHANSTATS, sizeof(chanstats)); } void freechanstats(chanstats *csp) { - csp->index=(chanindex *)freecs; - freecs=csp; + nsfree(POOL_CHANSTATS, csp); } diff --git a/core/nsmalloc.h b/core/nsmalloc.h index 2e46d6b1..aa1e8432 100644 --- a/core/nsmalloc.h +++ b/core/nsmalloc.h @@ -67,7 +67,8 @@ beginpools() { pool(GLINE), pool(TRUSTS), pool(SPAMSCAN2), - pool(ACHIEVEMENTS) + pool(ACHIEVEMENTS), + pool(CHANSTATS) } endpools() #undef pool