diff options
author | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2013-02-27 00:27:16 +0000 |
---|---|---|
committer | Chris Young <chris@unsatisfactorysoftware.co.uk> | 2013-02-27 00:27:16 +0000 |
commit | 617aa5e79e56b305619ef3661c4ae86952680ac9 (patch) | |
tree | 62d306fa88b466b27b502cd5fa458f7b81307aa8 /src | |
parent | 758155b3b4b44d51a9e5d6c79f9f6f66f2d5f25c (diff) | |
download | libwapcaplet-617aa5e79e56b305619ef3661c4ae86952680ac9.tar.gz libwapcaplet-617aa5e79e56b305619ef3661c4ae86952680ac9.tar.bz2 |
Don't artifically limit the number of memory pools we can have (note they don't get freed currently)
Diffstat (limited to 'src')
-rw-r--r-- | src/libwapcaplet.c | 39 | ||||
-rwxr-xr-x | src/mempool.c | 1 | ||||
-rwxr-xr-x | src/mempool.h | 1 |
3 files changed, 25 insertions, 16 deletions
diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c index 4cbb555..8126e62 100644 --- a/src/libwapcaplet.c +++ b/src/libwapcaplet.c @@ -36,7 +36,6 @@ lwc__calculate_hash(const char *str, size_t len) #define CSTR_OF(str) ((const char *)(str->string)) #define NR_BUCKETS_DEFAULT (4091) -#define MAX_MEM_POOLS 2 #define MEM_POOL_BLOCKS (65536) / (sizeof(lwc_string) + sizeof(void *)) typedef struct lwc_context_s { @@ -51,7 +50,7 @@ static lwc_context *ctx = NULL; #define LWC_ALLOC_STR() str_alloc() #define LWC_FREE_STR(p) str_free(p) -memory_pool_t *mp[MAX_MEM_POOLS] = { NULL, NULL }; +memory_pool_t *mp = NULL; typedef lwc_hash (*lwc_hasher)(const char *, size_t); typedef int (*lwc_strncmp)(const char *, const char *, size_t); @@ -63,29 +62,37 @@ static void str_free(void *p); static void *str_alloc(void) { void *p; - int i; - - for(i = 0; i < MAX_MEM_POOLS; i++) { - if(mp[i] == NULL) { - mp[i] = memory_pool_create(sizeof(lwc_string), MEM_POOL_BLOCKS); - if(mp[i] == NULL) return NULL; /* out of memory */ - } + memory_pool_t *mpc; + + if(mp == NULL) { + mp = memory_pool_create(sizeof(lwc_string), MEM_POOL_BLOCKS); + if(mp == NULL) return NULL; /* out of memory */ + } + + mpc = mp; - if((p = memory_pool_alloc(mp[i]))) { + do { + if((p = memory_pool_alloc(mpc))) { return p; } - } - return NULL; /* out of memory pools */ + + if(mpc->next == NULL) { + mpc->next = memory_pool_create(sizeof(lwc_string), MEM_POOL_BLOCKS); + if(mpc->next == NULL) return NULL; /* out of memory */ + } + } while((mpc = mpc->next)); + + return NULL; /* should never get here */ } static void str_free(void *p) { - int i; + memory_pool_t *mpc = mp; - for(i = 0; i < MAX_MEM_POOLS; i++) { - if(memory_pool_free(mp[i], p)) + do { + if(memory_pool_free(mpc, p)) return; - } + }while((mpc = mpc->next)); } static lwc_error diff --git a/src/mempool.c b/src/mempool.c index b0d0d26..5aa8f9d 100755 --- a/src/mempool.c +++ b/src/mempool.c @@ -22,6 +22,7 @@ memory_pool_t * memory_pool_create(size_t bs, size_t c) mp->block_size = bs; mp->count = c; mp->pool = NULL; + mp->next = NULL; #ifdef __amigaos4__ /* NB: This *always* allocates 64K, requests for more than 64K *must not* diff --git a/src/mempool.h b/src/mempool.h index 0d55a1b..6c0a663 100755 --- a/src/mempool.h +++ b/src/mempool.h @@ -12,6 +12,7 @@ typedef struct memory_pool_s size_t block_size; size_t count; bool ocm; + void *next; } __attribute__ ((__aligned__)) memory_pool_t; memory_pool_t * memory_pool_create(size_t bs, size_t c); |