Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-07 05:45:36 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-07 06:38:32 +0400
commitaee82b4b2c9ebc2ce3ef9e7fc28fd87d1691f045 (patch)
tree96a404b8c19b26372852a0d7abc4734d91e80036 /source/blender/blenlib/intern/BLI_mempool.c
parentaabf4154e511856277abcefe552dd96a0115dc7c (diff)
Mempool: fix own error in recent commit
chunks must be added in order for iteration.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 673dfdefe8e..1a32db745b7 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -97,7 +97,11 @@ typedef struct BLI_mempool_chunk {
* The mempool, stores and tracks memory \a chunks and elements within those chunks \a free.
*/
struct BLI_mempool {
- BLI_mempool_chunk *chunks;
+ BLI_mempool_chunk *chunks; /* single linked list of allocated chunks */
+ /* keep a pointer to the last, so we can append new chunks there
+ * this is needed for iteration so we can loop over chunks in the order added */
+ BLI_mempool_chunk *chunk_tail;
+
unsigned int esize; /* element size in bytes */
unsigned int csize; /* chunk size in bytes */
unsigned int pchunk; /* number of elements per chunk */
@@ -190,9 +194,17 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
char *addr;
unsigned int j;
- /* prepend */
- mpchunk->next = pool->chunks;
- pool->chunks = mpchunk;
+ /* append */
+ if (pool->chunk_tail) {
+ pool->chunk_tail->next = mpchunk;
+ }
+ else {
+ BLI_assert(pool->chunks == NULL);
+ pool->chunks = mpchunk;
+ }
+
+ mpchunk->next = NULL;
+ pool->chunk_tail = mpchunk;
if (pool->free == NULL) {
pool->free = CHUNK_DATA(mpchunk); /* start of the list */
@@ -273,6 +285,7 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem,
maxchunks = mempool_maxchunks(totelem, pchunk);
pool->chunks = NULL;
+ pool->chunk_tail = NULL;
pool->esize = esize;
pool->csize = esize * pchunk;
@@ -321,6 +334,8 @@ void *BLI_mempool_alloc(BLI_mempool *pool)
mempool_chunk_add(pool, mpchunk, NULL);
}
+ BLI_assert(pool->chunk_tail->next == NULL);
+
retval = pool->free;
if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) {
@@ -400,6 +415,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
first = pool->chunks;
mempool_chunk_free_all(first->next);
first->next = NULL;
+ pool->chunk_tail = first;
#ifdef USE_TOTALLOC
pool->totalloc = pool->pchunk;
@@ -626,6 +642,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
chunks_temp = pool->chunks;
pool->chunks = NULL;
+ pool->chunk_tail = NULL;
while ((mpchunk = chunks_temp)) {
chunks_temp = mpchunk->next;