diff options
author | Matias <matiassw@gmail.com> | 2013-06-25 16:59:44 -0400 |
---|---|---|
committer | Matias <matiassw@gmail.com> | 2013-06-25 16:59:44 -0400 |
commit | b40371d3a0772031d12f2782c10976413c6f34b9 (patch) | |
tree | 7aeed5544a9df524a834cc739d3f596b66d6a006 /src/common/ers.c | |
parent | 25914bae30eced388cf8640eead19fbb11a65ade (diff) | |
parent | 5785dbae3f513da20611e3147dadef2b9c911443 (diff) | |
download | hercules-b40371d3a0772031d12f2782c10976413c6f34b9.tar.gz hercules-b40371d3a0772031d12f2782c10976413c6f34b9.tar.bz2 hercules-b40371d3a0772031d12f2782c10976413c6f34b9.tar.xz hercules-b40371d3a0772031d12f2782c10976413c6f34b9.zip |
Merge branch 'master' of https://github.com/HerculesWS/Hercules
Diffstat (limited to 'src/common/ers.c')
-rw-r--r-- | src/common/ers.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/common/ers.c b/src/common/ers.c index 69b7609d6..22269a51f 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -84,6 +84,9 @@ typedef struct ers_cache // Objects in-use count unsigned int UsedObjs; + // Default = ERS_BLOCK_ENTRIES, can be adjusted for performance for individual cache sizes. + unsigned int ChunkSize; + // Linked list struct ers_cache *Next, *Prev; } ers_cache_t; @@ -136,6 +139,7 @@ static ers_cache_t *ers_find_cache(unsigned int size) cache->Used = 0; cache->UsedObjs = 0; cache->Max = 0; + cache->ChunkSize = ERS_BLOCK_ENTRIES; if (CacheList == NULL) { @@ -200,10 +204,10 @@ static void *ers_obj_alloc_entry(ERS self) RECREATE(instance->Cache->Blocks, unsigned char *, instance->Cache->Max); } - CREATE(instance->Cache->Blocks[instance->Cache->Used], unsigned char, instance->Cache->ObjectSize * ERS_BLOCK_ENTRIES); + CREATE(instance->Cache->Blocks[instance->Cache->Used], unsigned char, instance->Cache->ObjectSize * instance->Cache->ChunkSize); instance->Cache->Used++; - instance->Cache->Free = ERS_BLOCK_ENTRIES -1; + instance->Cache->Free = instance->Cache->ChunkSize -1; ret = &instance->Cache->Blocks[instance->Cache->Used - 1][instance->Cache->Free * instance->Cache->ObjectSize + sizeof(struct ers_list)]; } @@ -286,6 +290,18 @@ static void ers_obj_destroy(ERS self) aFree(instance); } +void ers_cache_size(ERS self, unsigned int new_size) { + struct ers_instance_t *instance = (struct ers_instance_t *)self; + + if (instance == NULL) {//change as per piotrhalaczkiewicz comment + ShowError("ers_cache_size: NULL object, skipping...\n"); + return; + } + + instance->Cache->ChunkSize = new_size; +} + + ERS ers_new(uint32 size, char *name, enum ERSOptions options) { struct ers_instance_t *instance; @@ -299,6 +315,7 @@ ERS ers_new(uint32 size, char *name, enum ERSOptions options) instance->VTable.free = ers_obj_free_entry; instance->VTable.entry_size = ers_obj_entry_size; instance->VTable.destroy = ers_obj_destroy; + instance->VTable.chunk_size = ers_cache_size; instance->Name = ( options & ERS_OPT_FREE_NAME ) ? aStrdup(name) : name; instance->Options = options; |