Skip to content

Commit a087e04

Browse files
committed
Merge remote-tracking branch 'origin/main' into P3481R2_bulk_issues2
2 parents bfecde6 + cb6d4e2 commit a087e04

26 files changed

Lines changed: 484 additions & 399 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ set(STDEXEC_ASIO_IMPLEMENTATION "boost" CACHE STRING "boost")
416416
set_property(CACHE STDEXEC_ASIO_IMPLEMENTATION PROPERTY STRINGS boost standalone)
417417

418418
if(STDEXEC_ENABLE_ASIO)
419-
set(STDEXEC_ASIO_USES_ASIO FALSE)
419+
set(STDEXEC_ASIO_USES_BOOST FALSE)
420420
set(STDEXEC_ASIO_USES_STANDALONE FALSE)
421421

422422
include(rapids-find)

cmake/clangd_compile_info.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2121
# Symlink the compile command output to the source dir, where clangd will find it.
2222
set(compile_commands_file "${CMAKE_BINARY_DIR}/compile_commands.json")
2323
set(compile_commands_link "${CMAKE_SOURCE_DIR}/compile_commands.json")
24-
message(STATUS "Creating symlink from ${compile_commands_link} to ${compile_commands_file}...")
24+
message(STATUS "Creating symlink from \"${compile_commands_file}\" to \"${compile_commands_link}\"...")
2525
stdexec_execute_non_fatal_process(COMMAND
2626
"${CMAKE_COMMAND}" -E rm -f "${compile_commands_link}")
2727
stdexec_execute_non_fatal_process(COMMAND

cmake/import_standalone_asio.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function(import_standalone_asio)
1111
set(options "")
1212
set(args TAG VERSION)
1313
set(multi_args "")
14-
cmake_parse_arguments(IMPORT_STANDALONE_ASIO "${options}" "${args}" "${multi_args}")
14+
cmake_parse_arguments(IMPORT_STANDALONE_ASIO "${options}" "${args}" "${multi_args}" ${ARGN})
1515

1616
CPMAddPackage("gh:chriskohlhoff/asio#${IMPORT_STANDALONE_ASIO_TAG}@${IMPORT_STANDALONE_ASIO_VERSION}")
1717

include/exec/__detail/__system_context_default_impl.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#pragma once
1717

1818
#include "__system_context_replaceability_api.hpp"
19-
#include "stdexec/execution.hpp"
20-
#include "exec/static_thread_pool.hpp"
19+
20+
#include "../../stdexec/execution.hpp"
21+
#include "../static_thread_pool.hpp"
2122
#if STDEXEC_ENABLE_LIBDISPATCH
22-
# include "exec/libdispatch_queue.hpp"
23+
# include "../libdispatch_queue.hpp" // IWYU pragma: keep
2324
#endif
2425

2526
#include <atomic>

include/exec/__detail/__system_context_replaceability_api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef STDEXEC_SYSTEM_CONTEXT_REPLACEABILITY_API_H
1818
#define STDEXEC_SYSTEM_CONTEXT_REPLACEABILITY_API_H
1919

20-
#include "stdexec/__detail/__execution_fwd.hpp"
20+
#include "../../stdexec/__detail/__execution_fwd.hpp"
2121

2222
#include <cstdint>
2323
#include <cstddef>

include/exec/libdispatch_queue.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# define __has_extension(x) false
2828
# endif
2929

30-
# include "stdexec/execution.hpp"
30+
# include "../stdexec/execution.hpp"
3131
# include <dispatch/dispatch.h>
3232

3333
namespace exec {

include/exec/start_now.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
#pragma once
1717

18-
#include "stdexec/__detail/__execution_fwd.hpp"
18+
#include "../stdexec/__detail/__execution_fwd.hpp"
1919

20-
#include "stdexec/__detail/__concepts.hpp"
21-
#include "stdexec/__detail/__env.hpp"
22-
#include "stdexec/__detail/__receivers.hpp"
23-
#include "stdexec/__detail/__senders.hpp"
24-
#include "stdexec/__detail/__meta.hpp"
20+
#include "../stdexec/__detail/__concepts.hpp"
21+
#include "../stdexec/__detail/__env.hpp"
22+
#include "../stdexec/__detail/__receivers.hpp"
23+
#include "../stdexec/__detail/__senders.hpp"
24+
#include "../stdexec/__detail/__meta.hpp"
2525

2626
#include "async_scope.hpp"
2727

include/exec/static_thread_pool.hpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ namespace exec {
617617
void notify_one_sleeping();
618618
void set_stealing();
619619
void clear_stealing();
620+
void set_sleeping();
621+
void clear_sleeping();
620622

621623
bwos::lifo_queue<task_base*, numa_allocator<task_base*>> local_queue_;
622624
__intrusive_queue<&task_base::next> pending_queue_{};
@@ -633,7 +635,7 @@ namespace exec {
633635
void run(std::uint32_t index) noexcept;
634636
void join() noexcept;
635637

636-
alignas(64) std::atomic<std::uint32_t> numThiefs_{};
638+
alignas(64) std::atomic<std::uint32_t> numActive_{};
637639
alignas(64) remote_queue_list remotes_;
638640
std::uint32_t threadCount_;
639641
std::uint32_t maxSteals_{threadCount_ + 1};
@@ -703,6 +705,7 @@ namespace exec {
703705
threads_.reserve(threadCount);
704706

705707
try {
708+
numActive_.store(threadCount << 16u, std::memory_order_relaxed);
706709
for (std::uint32_t i = 0; i < threadCount; ++i) {
707710
threads_.emplace_back([this, i] { run(i); });
708711
}
@@ -725,9 +728,9 @@ namespace exec {
725728
}
726729

727730
inline void static_thread_pool_::run(std::uint32_t threadIndex) noexcept {
731+
STDEXEC_ASSERT(threadIndex < threadCount_);
728732
// NOLINTNEXTLINE(bugprone-unused-return-value)
729733
numa_.bind_to_node(threadStates_[threadIndex]->numa_node());
730-
STDEXEC_ASSERT(threadIndex < threadCount_);
731734
while (true) {
732735
// Make a blocking call to de-queue a task if we don't already have one.
733736
auto [task, queueIndex] = threadStates_[threadIndex]->pop();
@@ -946,12 +949,31 @@ namespace exec {
946949
pending_queue_.prepend(std::move(tasks));
947950
}
948951

952+
inline void static_thread_pool_::thread_state::set_sleeping() {
953+
pool_->numActive_.fetch_sub(1u << 16u, std::memory_order_relaxed);
954+
}
955+
956+
// wakeup a worker thread and maintain the invariant that we always one active thief as long as a potential victim is awake
957+
inline void static_thread_pool_::thread_state::clear_sleeping() {
958+
const std::uint32_t numActive =
959+
pool_->numActive_.fetch_add(1u << 16u, std::memory_order_relaxed);
960+
if (numActive == 0) {
961+
notify_one_sleeping();
962+
}
963+
}
964+
949965
inline void static_thread_pool_::thread_state::set_stealing() {
950-
pool_->numThiefs_.fetch_add(1, std::memory_order_relaxed);
966+
const std::uint32_t diff = 1u - (1u << 16u);
967+
pool_->numActive_.fetch_add(diff, std::memory_order_relaxed);
951968
}
952969

970+
// put a thief to sleep but maintain the invariant that we always have one active thief as long as a potential victim is awake
953971
inline void static_thread_pool_::thread_state::clear_stealing() {
954-
if (pool_->numThiefs_.fetch_sub(1, std::memory_order_relaxed) == 1) {
972+
constexpr std::uint32_t diff = 1 - (1u << 16u);
973+
const std::uint32_t numActive = pool_->numActive_.fetch_sub(diff, std::memory_order_relaxed);
974+
const std::uint32_t numVictims = numActive >> 16u;
975+
const std::uint32_t numThiefs = numActive & 0xffffu;
976+
if (numThiefs == 1 && numVictims != 0) {
955977
notify_one_sleeping();
956978
}
957979
}
@@ -1003,9 +1025,14 @@ namespace exec {
10031025
if (result.task) {
10041026
return result;
10051027
}
1028+
set_sleeping();
10061029
cv_.wait(lock);
1030+
lock.unlock();
1031+
clear_sleeping();
1032+
}
1033+
if (lock.owns_lock()) {
1034+
lock.unlock();
10071035
}
1008-
lock.unlock();
10091036
state_.store(state::running, std::memory_order_relaxed);
10101037
result = try_pop();
10111038
}

include/exec/system_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <utility>
1919

20-
#include "stdexec/execution.hpp"
20+
#include "../stdexec/execution.hpp"
2121
#include "__detail/__system_context_replaceability_api.hpp"
2222

2323
#ifndef STDEXEC_SYSTEM_CONTEXT_SCHEDULE_OP_SIZE

include/execpools/asio/asio_thread_pool.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace execpools {
1515
public:
1616
asio_thread_pool()
1717
: pool_()
18-
, executor_(pool_.executor()) = default;
18+
, executor_(pool_.executor()) {
19+
}
1920

2021
explicit asio_thread_pool(uint32_t num_threads)
2122
: pool_(num_threads)

0 commit comments

Comments
 (0)