]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Use nsmalloc/nsfree for chanstats.
authorGunnar Beutner <redacted>
Tue, 30 Jul 2013 16:40:47 +0000 (18:40 +0200)
committerGunnar Beutner <redacted>
Tue, 30 Jul 2013 16:40:47 +0000 (18:40 +0200)
chanstats/chanstats.c
chanstats/chanstats.h
chanstats/chanstatsalloc.c
core/nsmalloc.h

index 6f072878e68a856ec8c1778c4949b3a1d6ce3b08..b6c6402a93b1830451c09ff7c9337a3e3af12b60 100644 (file)
@@ -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;
index e642926b3b69a5968cf4104a4bb2f29d1724e43b..f132bb2ca7400fa1f0d30a0070e6351b61ac8c34 100644 (file)
@@ -45,7 +45,6 @@ chanstats *findchanstatsifexists(const char *channame);
 
 /* chanstatsalloc.c */
 void cstsfreeall();
-void initchanstatsalloc();
 chanstats *getchanstats();
 void freechanstats(chanstats *csp);
 
index 2a8959b76ce108b1729b6443879d10c195cbe30d..1506a30185637c8b6cb63078bac8dea3ac1556a1 100644 (file)
@@ -1,66 +1,16 @@
 /* Allocators for chanstats */
 
 #include "chanstats.h"
-
-#include <stdlib.h>
-
-#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);
 }
index 2e46d6b1766215d4ef95a2459910c88ad8243178..aa1e8432990e9888b83c33f198b688d380916cbb 100644 (file)
@@ -67,7 +67,8 @@ beginpools() {
   pool(GLINE),
   pool(TRUSTS),
   pool(SPAMSCAN2),
-  pool(ACHIEVEMENTS)
+  pool(ACHIEVEMENTS),
+  pool(CHANSTATS)
 } endpools()
 
 #undef pool