Allocator: simplify using guarded allocator in C++ code
Using the `MEM_*` API from C++ code was a bit annoying: * When converting C to C++ code, one often has to add a type cast on returned `void *`. That leads to having the same type name three times in the same line. This patch reduces the amount to two and removes the `sizeof(...)` from the line. * The existing alternative of using `OBJECT_GUARDED_NEW` looks a out of place compared to other allocation methods. Sometimes `MEM_CXX_CLASS_ALLOC_FUNCS` can be used when structs are defined in C++ code. It doesn't look great but it's definitely better. The downside is that it makes the name of the allocation less useful. That's because the same name is used for all allocations of a type, independend of where it is allocated. This patch introduces three new functions: `MEM_new`, `MEM_cnew` and `MEM_delete`. These cover the majority of use cases (array allocation is not covered). The `OBJECT_GUARDED_*` macros are removed because they are not needed anymore. Differential Revision: https://developer.blender.org/D13502
This commit is contained in:
@@ -50,8 +50,8 @@ void BLI_task_scheduler_init()
|
||||
if (num_threads_override > 0) {
|
||||
/* Override number of threads. This settings is used within the lifetime
|
||||
* of tbb::global_control, so we allocate it on the heap. */
|
||||
task_scheduler_global_control = OBJECT_GUARDED_NEW(
|
||||
tbb::global_control, tbb::global_control::max_allowed_parallelism, num_threads_override);
|
||||
task_scheduler_global_control = MEM_new<tbb::global_control>(
|
||||
__func__, tbb::global_control::max_allowed_parallelism, num_threads_override);
|
||||
task_scheduler_num_threads = num_threads_override;
|
||||
}
|
||||
else {
|
||||
@@ -69,7 +69,7 @@ void BLI_task_scheduler_init()
|
||||
void BLI_task_scheduler_exit()
|
||||
{
|
||||
#ifdef WITH_TBB_GLOBAL_CONTROL
|
||||
OBJECT_GUARDED_DELETE(task_scheduler_global_control, tbb::global_control);
|
||||
MEM_delete(task_scheduler_global_control);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user