From d1fe291a33397aea363190b02832eb8cc803d1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Ospina=20De=20Los=20R=C3=ADos?= Date: Tue, 16 Apr 2024 17:51:21 +0200 Subject: [PATCH] C++14 compatible alloc --- src/tbb/global_control.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tbb/global_control.cpp b/src/tbb/global_control.cpp index 6f23e4e27b..e90f39e760 100644 --- a/src/tbb/global_control.cpp +++ b/src/tbb/global_control.cpp @@ -27,7 +27,10 @@ #include "misc.h" #include +#include +#include #include +#include namespace tbb { namespace detail { @@ -139,7 +142,7 @@ class alignas(max_nfs_size) lifetime_control : public control_storage { } }; -struct control_storage_instance { +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; @@ -149,7 +152,8 @@ static control_storage_instance* control_storage_instance_ptr = nullptr; static control_storage *controls[4] = {nullptr, nullptr, nullptr, nullptr}; void global_control_acquire() { - control_storage_instance_ptr = new control_storage_instance{}; + 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; @@ -157,9 +161,11 @@ void global_control_acquire() { } void global_control_release() { - for (auto& ptr : controls) + for (auto& ptr : controls) { ptr = nullptr; - delete control_storage_instance_ptr; + } + control_storage_instance_ptr->~control_storage_instance(); + free(std::exchange(control_storage_instance_ptr, nullptr)); } void global_control_lock() {