Skip to content

Commit

Permalink
use cache aligned allocator for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
SoilRos committed Apr 17, 2024
1 parent d1fe291 commit 7aa6d21
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/tbb/global_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,10 +28,8 @@
#include "misc.h"

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

namespace tbb {
namespace detail {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7aa6d21

Please sign in to comment.