Skip to content

Commit

Permalink
Use TBB helper functions instead of straightforward code
Browse files Browse the repository at this point in the history
  • Loading branch information
YexuanXiao committed Sep 24, 2024
1 parent ee88150 commit 94fc13f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
26 changes: 6 additions & 20 deletions include/oneapi/tbb/concurrent_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ class concurrent_queue {
if (my_queue_representation == other.my_queue_representation)
return *this;
clear();
if (queue_allocator_traits::propagate_on_container_move_assignment::value) {
my_allocator = other.my_allocator;
}
tbb::detail::copy_assign_allocators(my_allocator, other.my_allocator);
my_queue_representation->assign(*other.my_queue_representation, my_allocator, copy_construct_item);
return *this;
}
Expand All @@ -152,7 +150,7 @@ class concurrent_queue {
return *this;
clear();
if (queue_allocator_traits::propagate_on_container_move_assignment::value) {
my_allocator = std::move(other.my_allocator);
tbb::detail::move_assign_allocators(my_allocator, other.my_allocator);
internal_swap(other);
} else {
if (my_allocator == other.my_allocator) {
Expand Down Expand Up @@ -182,12 +180,7 @@ class concurrent_queue {
}

void swap ( concurrent_queue& other ) {
if (queue_allocator_traits::propagate_on_container_swap::value) {
using std::swap;
swap(my_allocator, other.my_allocator);
} else {
__TBB_ASSERT(my_allocator == other.my_allocator, "unequal allocators");
}
tbb::detail::swap_allocators(my_allocator, other.my_allocator);
internal_swap(other);
}

Expand Down Expand Up @@ -425,9 +418,7 @@ class concurrent_bounded_queue {
if (my_queue_representation == other.my_queue_representation)
return *this;
clear();
if (queue_allocator_traits::propagate_on_container_move_assignment::value) {
my_allocator = other.my_allocator;
}
tbb::detail::copy_assign_allocators(my_allocator, other.my_allocator);
my_queue_representation->assign(*other.my_queue_representation, my_allocator, copy_construct_item);
return *this;
}
Expand All @@ -437,7 +428,7 @@ class concurrent_bounded_queue {
return *this;
clear();
if (queue_allocator_traits::propagate_on_container_move_assignment::value) {
my_allocator = std::move(other.my_allocator);
tbb::detail::move_assign_allocators(my_allocator, other.my_allocator);
internal_swap(other);
} else {
if (my_allocator == other.my_allocator) {
Expand Down Expand Up @@ -467,12 +458,7 @@ class concurrent_bounded_queue {
}

void swap ( concurrent_bounded_queue& other ) {
if (queue_allocator_traits::propagate_on_container_swap::value) {
using std::swap;
swap(my_allocator, other.my_allocator);
} else {
__TBB_ASSERT(my_allocator == other.my_allocator, "unequal allocators");
}
tbb::detail::swap_allocators(my_allocator, other.my_allocator);
internal_swap(other);
}

Expand Down
5 changes: 4 additions & 1 deletion include/oneapi/tbb/detail/_allocator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ void swap_allocators_impl( Allocator& lhs, Allocator& rhs, /*pocs = */ std::true
}

template <typename Allocator>
void swap_allocators_impl( Allocator&, Allocator&, /*pocs = */ std::false_type ) {}
void swap_allocators_impl( Allocator& lhs, Allocator& rhs, /*pocs = */ std::false_type ) {
// If the lhs and rhs are not equal, the behavior is undefined
__TBB_ASSERT(lhs == rhs, "unequal allocators");
}

// Swaps allocators only if propagate_on_container_swap is true
template <typename Allocator>
Expand Down

0 comments on commit 94fc13f

Please sign in to comment.