From b3afbcab8ff2330c1473647be330a3ffe9b11885 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 8 Feb 2014 06:07:10 +1100 Subject: ListBase API: add utility api funcs for clearing and checking empty --- source/blender/blenlib/intern/BLI_args.c | 2 +- source/blender/blenlib/intern/BLI_mempool.c | 6 +++--- source/blender/blenlib/intern/scanfill.c | 18 +++++++++--------- source/blender/blenlib/intern/task.c | 2 +- source/blender/blenlib/intern/threads.c | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'source/blender/blenlib/intern') 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); -- cgit v1.2.3