diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-06-09 15:49:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-06-09 17:55:04 +0300 |
commit | 14f3b2cdad2d7b00ce3ea27bf8eb0087ac2a6cbd (patch) | |
tree | 889d20ad5cf627057bb619e18ec47d39cabafc99 /source/blender/blenlib/intern/BLI_mempool.c | |
parent | f546b0800b9121b24b1292f1ec602ed9964d1848 (diff) |
BLI_task: add TLS support to BLI_task_parallel_mempool
Support thread local storage for BLI_task_parallel_mempool,
as well as support for the reduce and free callbacks.
mempool_iter_threadsafe_* functions have been moved into a private
header thats only shared between task_iterator.c and BLI_mempool.c
so the TLS can be made part of the iterator array without having to
rely on passing in struct offsets.
Add test task.MempoolIterTLS that ensures reduce and free
are working as expected.
Reviewed By: mont29
Ref D11548
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 75f934c1fb8..cf0021609b5 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -36,7 +36,8 @@ #include "BLI_utildefines.h" -#include "BLI_mempool.h" /* own include */ +#include "BLI_mempool.h" /* own include */ +#include "BLI_mempool_private.h" /* own include */ #include "MEM_guardedalloc.h" @@ -558,33 +559,31 @@ void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) * * See BLI_task_parallel_mempool implementation for detailed usage example. */ -BLI_mempool_iter *BLI_mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) { BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER); - BLI_mempool_iter *iter_arr = MEM_mallocN(sizeof(*iter_arr) * num_iter, __func__); + ParallelMempoolTaskData *iter_arr = MEM_mallocN(sizeof(*iter_arr) * num_iter, __func__); BLI_mempool_chunk **curchunk_threaded_shared = MEM_mallocN(sizeof(void *), __func__); - BLI_mempool_iternew(pool, iter_arr); - - *curchunk_threaded_shared = iter_arr->curchunk; - iter_arr->curchunk_threaded_shared = curchunk_threaded_shared; + BLI_mempool_iternew(pool, &iter_arr->iter); + *curchunk_threaded_shared = iter_arr->iter.curchunk; + iter_arr->iter.curchunk_threaded_shared = curchunk_threaded_shared; for (size_t i = 1; i < num_iter; i++) { - iter_arr[i] = iter_arr[0]; - *curchunk_threaded_shared = iter_arr[i].curchunk = ((*curchunk_threaded_shared) ? - (*curchunk_threaded_shared)->next : - NULL); + iter_arr[i].iter = iter_arr[0].iter; + *curchunk_threaded_shared = iter_arr[i].iter.curchunk = + ((*curchunk_threaded_shared) ? (*curchunk_threaded_shared)->next : NULL); } return iter_arr; } -void BLI_mempool_iter_threadsafe_free(BLI_mempool_iter *iter_arr) +void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) { - BLI_assert(iter_arr->curchunk_threaded_shared != NULL); + BLI_assert(iter_arr->iter.curchunk_threaded_shared != NULL); - MEM_freeN(iter_arr->curchunk_threaded_shared); + MEM_freeN(iter_arr->iter.curchunk_threaded_shared); MEM_freeN(iter_arr); } |