Skip to content

Commit

Permalink
C++14 compatible alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
SoilRos committed Apr 16, 2024
1 parent 531981f commit d1fe291
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/tbb/global_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
#include "misc.h"

#include <atomic>
#include <stdlib.h>
#include <new>
#include <set>
#include <utility>

namespace tbb {
namespace detail {
Expand Down Expand Up @@ -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;
Expand All @@ -149,17 +152,20 @@ 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;
controls[3] = &control_storage_instance_ptr->lifetime_ctl;
}

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() {
Expand Down

0 comments on commit d1fe291

Please sign in to comment.