diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-02-07 23:07:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-02-07 23:24:05 +0400 |
commit | b3afbcab8ff2330c1473647be330a3ffe9b11885 (patch) | |
tree | e86b9c7d9676e63b8da92da79889dee13b8be186 /source/blender/blenlib | |
parent | 1c24d954f4ac63f22b703756b6664a4ad1b363d4 (diff) |
ListBase API: add utility api funcs for clearing and checking empty
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_args.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/scanfill.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/task.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/threads.c | 4 |
6 files changed, 23 insertions, 16 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 0927620a2c6..77490929efb 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -77,6 +77,13 @@ void BLI_reverselist(struct ListBase *lb); void BLI_rotatelist_first(struct ListBase *lb, void *vlink); void BLI_rotatelist_last(struct ListBase *lb, void *vlink); +/** + * Utility functions to avoid first/last references inline all over. + */ +BLI_INLINE bool BLI_listbase_is_single(const struct ListBase *lb) { return (lb->first && lb->first == lb->last); } +BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb) { return (lb->first == NULL); } +BLI_INLINE void BLI_listbase_clear(struct ListBase *lb) { lb->first = lb->last = NULL; } + /* create a generic list node containing link to provided data */ struct LinkData *BLI_genericNodeN(void *data); diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index fdef0d69539..fb35b55a935 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -122,7 +122,7 @@ bArgs *BLI_argsInit(int argc, const char **argv) bArgs *ba = MEM_callocN(sizeof(bArgs), "bArgs"); ba->passes = MEM_callocN(sizeof(int) * argc, "bArgs passes"); ba->items = BLI_ghash_new(keyhash, keycmp, "bArgs passes gh"); - ba->docs.first = ba->docs.last = NULL; + BLI_listbase_clear(&ba->docs); ba->argc = argc; ba->argv = argv; diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 1321f006e36..7dc43bb1494 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -233,7 +233,7 @@ static void mempool_chunk_free_all(ListBase *chunks, const unsigned int flag) mpchunk_next = mpchunk->next; mempool_chunk_free(mpchunk, flag); } - chunks->first = chunks->last = NULL; + BLI_listbase_clear(chunks); } BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem, @@ -268,7 +268,7 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem, pool->flag = flag; pool->pchunk = pchunk; pool->csize = esize * pchunk; - pool->chunks.first = pool->chunks.last = NULL; + BLI_listbase_clear(&pool->chunks); pool->free = NULL; /* mempool_chunk_add assigns */ pool->maxchunks = maxchunks; #ifdef USE_TOTALLOC @@ -598,7 +598,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve) #endif chunks_temp = pool->chunks; - pool->chunks.first = pool->chunks.last = NULL; + BLI_listbase_clear(&pool->chunks); while ((mpchunk = BLI_pophead(&chunks_temp))) { lasttail = mempool_chunk_add(pool, mpchunk, lasttail); diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 46ab2db87f5..ae0760eb30e 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -754,9 +754,9 @@ void BLI_scanfill_end(ScanFillContext *sf_ctx) BLI_memarena_free(sf_ctx->arena); sf_ctx->arena = NULL; - sf_ctx->fillvertbase.first = sf_ctx->fillvertbase.last = NULL; - sf_ctx->filledgebase.first = sf_ctx->filledgebase.last = NULL; - sf_ctx->fillfacebase.first = sf_ctx->fillfacebase.last = NULL; + BLI_listbase_clear(&sf_ctx->fillvertbase); + BLI_listbase_clear(&sf_ctx->filledgebase); + BLI_listbase_clear(&sf_ctx->fillfacebase); } void BLI_scanfill_end_arena(ScanFillContext *sf_ctx, MemArena *arena) @@ -764,9 +764,9 @@ void BLI_scanfill_end_arena(ScanFillContext *sf_ctx, MemArena *arena) BLI_memarena_clear(arena); BLI_assert(sf_ctx->arena == arena); - sf_ctx->fillvertbase.first = sf_ctx->fillvertbase.last = NULL; - sf_ctx->filledgebase.first = sf_ctx->filledgebase.last = NULL; - sf_ctx->fillfacebase.first = sf_ctx->fillfacebase.last = NULL; + BLI_listbase_clear(&sf_ctx->fillvertbase); + BLI_listbase_clear(&sf_ctx->filledgebase); + BLI_listbase_clear(&sf_ctx->fillfacebase); } unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const float nor_proj[3]) @@ -994,7 +994,7 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const } } } - if (sf_ctx->filledgebase.first == NULL) { + if (BLI_listbase_is_empty(&sf_ctx->filledgebase)) { /* printf("All edges removed\n"); */ return 0; } @@ -1112,8 +1112,8 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const tempve.last = sf_ctx->fillvertbase.last; temped.first = sf_ctx->filledgebase.first; temped.last = sf_ctx->filledgebase.last; - sf_ctx->fillvertbase.first = sf_ctx->fillvertbase.last = NULL; - sf_ctx->filledgebase.first = sf_ctx->filledgebase.last = NULL; + BLI_listbase_clear(&sf_ctx->fillvertbase); + BLI_listbase_clear(&sf_ctx->filledgebase); pf = pflist; for (a = 0; a < poly; a++) { diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 1ac4045ea49..8d867b9f295 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -156,7 +156,7 @@ TaskScheduler *BLI_task_scheduler_create(int num_threads) * threads, so we keep track of the number of users. */ scheduler->do_exit = false; - scheduler->queue.first = scheduler->queue.last = NULL; + BLI_listbase_clear(&scheduler->queue); BLI_mutex_init(&scheduler->queue_mutex); BLI_condition_init(&scheduler->queue_cond); diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 0b8f5dfdde5..5d8c1af6c7f 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -184,7 +184,7 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) int a; if (threadbase != NULL && tot > 0) { - threadbase->first = threadbase->last = NULL; + BLI_listbase_clear(threadbase); if (tot > RE_MAX_THREAD) tot = RE_MAX_THREAD; else if (tot < 1) tot = 1; @@ -318,7 +318,7 @@ void BLI_end_threads(ListBase *threadbase) /* only needed if there's actually some stuff to end * this way we don't end up decrementing thread_levels on an empty threadbase * */ - if (threadbase && threadbase->first != NULL) { + if (threadbase && (BLI_listbase_is_empty(threadbase) == false)) { for (tslot = threadbase->first; tslot; tslot = tslot->next) { if (tslot->avail == 0) { pthread_join(tslot->pthread, NULL); |