Skip to content

Commit

Permalink
Merge pull request NVIDIA#1263 from NVIDIA/msvc-portability-fixes
Browse files Browse the repository at this point in the history
fix some narrowing conversion errors on MSVC
  • Loading branch information
ericniebler authored Feb 28, 2024
2 parents bc6d811 + 517eace commit 54c9cbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions examples/benchmark/static_thread_pool_old.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ namespace exec_old {

STDEXEC_ASSERT(task || queueIndex == threadIndex);
// Make a blocking call to de-queue a task if we don't already have one.
if (!task && !(task = threadStates_[queueIndex].pop()))
return; // pop() only returns null when request_stop() was called.
if (!task) {
task = threadStates_[queueIndex].pop();
if (!task)
return; // pop() only returns null when request_stop() was called.
}

task->__execute(task, queueIndex);
}
Expand Down
14 changes: 8 additions & 6 deletions include/exec/__detail/__bwos_lifo_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ namespace exec::bwos {
lifo_queue_error_code lifo_queue<Tp, Allocator>::block_type::put(Tp value) noexcept {
std::uint64_t back = tail_.load(std::memory_order_relaxed);
if (back < block_size()) [[likely]] {
ring_buffer_[back] = static_cast<Tp &&>(value);
ring_buffer_[static_cast<std::size_t>(back)] = static_cast<Tp &&>(value);
tail_.store(back + 1, std::memory_order_release);
return lifo_queue_error_code::success;
}
Expand All @@ -395,7 +395,7 @@ namespace exec::bwos {
Iterator lifo_queue<Tp, Allocator>::block_type::bulk_put(Iterator first, Sentinel last) noexcept {
std::uint64_t back = tail_.load(std::memory_order_relaxed);
while (first != last && back < block_size()) {
ring_buffer_[back] = static_cast<Tp &&>(*first);
ring_buffer_[static_cast<std::size_t>(back)] = static_cast<Tp &&>(*first);
++back;
++first;
}
Expand All @@ -413,7 +413,7 @@ namespace exec::bwos {
if (front == back) [[unlikely]] {
return {lifo_queue_error_code::empty, nullptr};
}
Tp value = static_cast<Tp &&>(ring_buffer_[back - 1]);
Tp value = static_cast<Tp &&>(ring_buffer_[static_cast<std::size_t>(back - 1)]);
tail_.store(back - 1, std::memory_order_release);
return {lifo_queue_error_code::success, value};
}
Expand All @@ -435,7 +435,7 @@ namespace exec::bwos {
result.status = lifo_queue_error_code::conflict;
return result;
}
result.value = static_cast<Tp &&>(ring_buffer_[spos]);
result.value = static_cast<Tp &&>(ring_buffer_[static_cast<std::size_t>(spos)]);
steal_head_.fetch_add(1, std::memory_order_release);
result.status = lifo_queue_error_code::success;
return result;
Expand All @@ -445,10 +445,12 @@ namespace exec::bwos {
takeover_result lifo_queue<Tp, Allocator>::block_type::takeover() noexcept {
std::uint64_t spos = steal_tail_.exchange(block_size(), std::memory_order_relaxed);
if (spos == block_size()) [[unlikely]] {
return {head_.load(std::memory_order_relaxed), tail_.load(std::memory_order_relaxed)};
return {static_cast<std::size_t>(head_.load(std::memory_order_relaxed)),
static_cast<std::size_t>(tail_.load(std::memory_order_relaxed))};
}
head_.store(spos, std::memory_order_relaxed);
return {spos, tail_.load(std::memory_order_relaxed)};
return {static_cast<std::size_t>(spos),
static_cast<std::size_t>(tail_.load(std::memory_order_relaxed))};
}

template <class Tp, class Allocator>
Expand Down

0 comments on commit 54c9cbd

Please sign in to comment.