diff options
author | celest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2005-03-23 15:03:21 +0000 |
---|---|---|
committer | celest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2005-03-23 15:03:21 +0000 |
commit | 7d3fedfa5c264169c544fe3ec977229c50e4baa2 (patch) | |
tree | d9b765647b15ee2a15a7a5d851c603be2eeb1a0d /src | |
parent | 77fa315a25b08c429758d109b08a67a6e6a52e50 (diff) | |
download | hercules-7d3fedfa5c264169c544fe3ec977229c50e4baa2.tar.gz hercules-7d3fedfa5c264169c544fe3ec977229c50e4baa2.tar.bz2 hercules-7d3fedfa5c264169c544fe3ec977229c50e4baa2.tar.xz hercules-7d3fedfa5c264169c544fe3ec977229c50e4baa2.zip |
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1274 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/common/db.c | 67 | ||||
-rw-r--r-- | src/common/db.h | 3 |
2 files changed, 68 insertions, 2 deletions
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 <stdio.h> #include <stdlib.h> #include <string.h> @@ -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;i<dbn_root_num;i++) + if (dbn_root[i]) + aFree(dbn_root[i]); + + dbn_root_rest=0; + dbn_root_num=0; + + return; +} +#else +void exit_dbn(void) +{ + int i = 0; + struct dbn *p = head, *p2; + while (p) { + p2 = p->next; + 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 diff --git a/src/common/db.h b/src/common/db.h index 11ed4f3e1..8b37e15ad 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -14,6 +14,8 @@ struct dbn { void *key; void *data; int deleted; // 削除済みフラグ(db_foreach) + struct dbn *next; + struct dbn *prev; }; struct dbt { @@ -59,5 +61,6 @@ struct dbn* db_insert(struct dbt *table,void* key,void* data); void* db_erase(struct dbt *table,void* key); void db_foreach(struct dbt*,int(*)(void*,void*,va_list),...); void db_final(struct dbt*,int(*)(void*,void*,va_list),...); +void exit_dbn(void); #endif |