From 7d3fedfa5c264169c544fe3ec977229c50e4baa2 Mon Sep 17 00:00:00 2001 From: celest Date: Wed, 23 Mar 2005 15:03:21 +0000 Subject: git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1274 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/db.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'src/common/db.c') diff --git a/src/common/db.c b/src/common/db.c index 71077ac06..377128e8f 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -1,5 +1,4 @@ // $Id: db.c,v 1.2 2004/09/23 14:43:06 MouseJstr Exp $ -// #define MALLOC_DBN #include #include #include @@ -12,8 +11,16 @@ #include "memwatch.h" #endif -#define ROOT_SIZE 4096 +//#define MALLOC_DBN + +// Backup cleaning routine in case the core doesn't do so properly, +// only enabled if malloc_dbn is not defined. +// As a temporary solution the root of the problem should still be found and fixed +struct dbn *head; +struct dbn *tail; + #ifdef MALLOC_DBN +#define ROOT_SIZE 4096 static struct dbn *dbn_root[512], *dbn_free; static int dbn_root_rest=0,dbn_root_num=0; @@ -40,6 +47,34 @@ static void free_dbn(struct dbn* add_dbn) add_dbn->parent = dbn_free; dbn_free = add_dbn; } + +void exit_dbn(void) +{ + int i; + + for (i=0;inext; + aFree(p); + p = p2; + i++; + } + //printf ("freed %d stray dbn\n", i); + return; +} #endif // maybe change the void* to const char* ??? @@ -438,6 +473,16 @@ struct dbn* db_insert(struct dbt *table,void* key,void* data) p->data = data; p->color = RED; p->deleted = 0; + p->prev = NULL; + p->next = NULL; + if (head == NULL) + head = tail = p; + else { + p->prev = tail; + tail->next = p; + tail = p; + } + if(c==0){ // hash entry is empty table->ht[hash] = p; p->color = BLACK; @@ -454,6 +499,7 @@ struct dbn* db_insert(struct dbt *table,void* key,void* data) } } table->item_count++; + return p; } @@ -497,6 +543,15 @@ void* db_erase(struct dbt *table,void* key) } } else { db_rebalance_erase(p,&table->ht[hash]); + if (p->prev) + p->prev->next = p->next; + else + head = p->next; + if (p->next) + p->next->prev = p->prev; + else + tail = p->prev; + #ifdef MALLOC_DBN free_dbn(p); #else @@ -584,6 +639,14 @@ void db_final(struct dbt *table,int (*func)(void*,void*,va_list),...) pn=stack[--sp]; } } + if (p->prev) + p->prev->next = p->next; + else + head = p->next; + if (p->next) + p->next->prev = p->prev; + else + tail = p->prev; #ifdef MALLOC_DBN free_dbn(p); #else -- cgit v1.2.3-70-g09d2