From 7aa6d219d6aed02a61657a2e961712f3afd63e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Ospina=20De=20Los=20R=C3=ADos?= Date: Wed, 17 Apr 2024 12:10:35 +0200 Subject: [PATCH] use cache aligned allocator for backwards compatibility --- src/tbb/global_control.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/tbb/global_control.cpp b/src/tbb/global_control.cpp index e90f39e760..b4f9eb0570 100644 --- a/src/tbb/global_control.cpp +++ b/src/tbb/global_control.cpp @@ -17,6 +17,7 @@ #include "oneapi/tbb/detail/_config.h" #include "oneapi/tbb/detail/_template_helpers.h" +#include "oneapi/tbb/cache_aligned_allocator.h" #include "oneapi/tbb/global_control.h" #include "oneapi/tbb/tbb_allocator.h" #include "oneapi/tbb/spin_mutex.h" @@ -27,10 +28,8 @@ #include "misc.h" #include -#include #include #include -#include namespace tbb { namespace detail { @@ -142,30 +141,21 @@ class alignas(max_nfs_size) lifetime_control : public control_storage { } }; -struct alignas(max_nfs_size) control_storage_instance { - allowed_parallelism_control allowed_parallelism_ctl; - stack_size_control stack_size_ctl; - terminate_on_exception_control terminate_on_exception_ctl; - lifetime_control lifetime_ctl; -}; -static control_storage_instance* control_storage_instance_ptr = nullptr; static control_storage *controls[4] = {nullptr, nullptr, nullptr, nullptr}; void global_control_acquire() { - auto ptr = aligned_alloc(max_nfs_size, sizeof(control_storage_instance)); - control_storage_instance_ptr = new (ptr) control_storage_instance{}; - controls[0] = &control_storage_instance_ptr->allowed_parallelism_ctl; - controls[1] = &control_storage_instance_ptr->stack_size_ctl; - controls[2] = &control_storage_instance_ptr->terminate_on_exception_ctl; - controls[3] = &control_storage_instance_ptr->lifetime_ctl; + controls[0] = new (cache_aligned_allocate(sizeof(allowed_parallelism_control))) allowed_parallelism_control{}; + controls[1] = new (cache_aligned_allocate(sizeof(stack_size_control))) stack_size_control{}; + controls[2] = new (cache_aligned_allocate(sizeof(terminate_on_exception_control))) terminate_on_exception_control{}; + controls[3] = new (cache_aligned_allocate(sizeof(lifetime_control))) lifetime_control{}; } void global_control_release() { for (auto& ptr : controls) { + ptr->~control_storage(); + cache_aligned_deallocate(ptr); ptr = nullptr; } - control_storage_instance_ptr->~control_storage_instance(); - free(std::exchange(control_storage_instance_ptr, nullptr)); } void global_control_lock() {