Skip to content

Commit 47bb920

Browse files
authored
fix a circular dependence of static_thread_pool.hpp (#1999)
* fix a circular dependence of `static_thread_pool.hpp` fixes #1990
1 parent 2fd7edb commit 47bb920

7 files changed

Lines changed: 91 additions & 40 deletions

File tree

examples/benchmark/common.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include <stdexec/execution.hpp>
18+
1719
#include <exec/detail/numa.hpp>
1820
#include <exec/static_thread_pool.hpp>
1921

include/exec/sequence/iterate.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020

2121
#if !STDEXEC_NO_STDCPP_RANGES()
2222

23+
# include "../../stdexec/__detail/__concepts.hpp"
24+
# include "../../stdexec/__detail/__connect.hpp"
25+
# include "../../stdexec/__detail/__env.hpp"
26+
# include "../../stdexec/__detail/__execution_fwd.hpp"
27+
# include "../../stdexec/__detail/__operation_states.hpp"
2328
# include "../../stdexec/__detail/__optional.hpp"
24-
# include "../../stdexec/execution.hpp"
29+
# include "../../stdexec/__detail/__receivers.hpp"
30+
# include "../../stdexec/__detail/__schedulers.hpp"
31+
# include "../../stdexec/__detail/__sender_concepts.hpp"
2532

2633
# include "../detail/basic_sequence.hpp"
2734
# include "../sender_for.hpp"

include/exec/sequence_senders.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@
1616
*/
1717
#pragma once
1818

19-
#include "../stdexec/execution.hpp"
19+
#include "../stdexec/__detail/__execution_fwd.hpp"
2020

21+
#include "../stdexec/__detail/__completion_signatures.hpp"
2122
#include "../stdexec/__detail/__concepts.hpp"
23+
#include "../stdexec/__detail/__connect.hpp"
24+
#include "../stdexec/__detail/__debug.hpp"
2225
#include "../stdexec/__detail/__diagnostics.hpp"
26+
#include "../stdexec/__detail/__env.hpp"
27+
#include "../stdexec/__detail/__just.hpp"
2328
#include "../stdexec/__detail/__meta.hpp"
29+
#include "../stdexec/__detail/__receivers.hpp"
30+
#include "../stdexec/__detail/__senders.hpp"
31+
#include "../stdexec/__detail/__stop_token.hpp"
32+
#include "../stdexec/__detail/__tag_invoke.hpp"
33+
#include "../stdexec/__detail/__transform_sender.hpp"
34+
#include "../stdexec/__detail/__type_traits.hpp"
35+
#include "../stdexec/__detail/__utility.hpp"
36+
#include "../stdexec/stop_token.hpp"
37+
2438
#include "completion_signatures.hpp"
2539

2640
STDEXEC_PRAGMA_PUSH()
@@ -565,7 +579,7 @@ namespace experimental::execution
565579
struct __sequence_type_check_failure //
566580
: STDEXEC::__compile_time_error<__sequence_type_check_failure<_Data, _What...>>
567581
{
568-
static_assert(std::is_nothrow_move_constructible_v<_Data>,
582+
static_assert(STDEXEC::__nothrow_move_constructible<_Data>,
569583
"The data member of sender_type_check_failure must be nothrow move "
570584
"constructible.");
571585

@@ -783,11 +797,9 @@ namespace experimental::execution
783797

784798
static_assert(sequence_sender<_Sequence>
785799
|| has_sequence_item_types<_Sequence, env_of_t<_Receiver>>,
786-
"The first argument to " STDEXEC_PP_STRINGIZE(STDEXEC) "::subscribe must be "
787-
"a sequence sender");
800+
"The first argument to exec::subscribe must be a sequence sender");
788801
static_assert(receiver<_Receiver>,
789-
"The second argument to " STDEXEC_PP_STRINGIZE(STDEXEC) "::subscribe must be "
790-
"a receiver");
802+
"The second argument to exec::subscribe must be a receiver");
791803
#if STDEXEC_ENABLE_EXTRA_TYPE_CHECKING()
792804
static_assert(__type_check_arguments<__tfx_seq_t, _Receiver>());
793805
#endif

include/exec/static_thread_pool.hpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@
1818
#pragma once
1919

2020
#include "../stdexec/__detail/__atomic.hpp"
21+
#include "../stdexec/__detail/__bulk.hpp"
22+
#include "../stdexec/__detail/__completion_signatures.hpp"
23+
#include "../stdexec/__detail/__concepts.hpp"
2124
#include "../stdexec/__detail/__config.hpp"
25+
#include "../stdexec/__detail/__domain.hpp"
26+
#include "../stdexec/__detail/__execution_fwd.hpp"
27+
#include "../stdexec/__detail/__execution_legacy.hpp"
28+
#include "../stdexec/__detail/__get_completion_signatures.hpp"
2229
#include "../stdexec/__detail/__intrusive_queue.hpp"
23-
#include "../stdexec/__detail/__manual_lifetime.hpp" // IWYU pragma: keep
24-
#include "../stdexec/__detail/__meta.hpp" // IWYU pragma: keep
25-
#include "../stdexec/execution.hpp"
30+
#include "../stdexec/__detail/__manual_lifetime.hpp"
31+
#include "../stdexec/__detail/__meta.hpp"
32+
#include "../stdexec/__detail/__optional.hpp"
33+
#include "../stdexec/__detail/__receivers.hpp"
34+
#include "../stdexec/__detail/__transform_completion_signatures.hpp"
35+
#include "../stdexec/__detail/__tuple.hpp"
36+
#include "../stdexec/__detail/__type_traits.hpp"
37+
#include "../stdexec/__detail/__variant.hpp"
38+
2639
#include "detail/atomic_intrusive_queue.hpp"
2740
#include "detail/bwos_lifo_queue.hpp"
2841
#include "detail/numa.hpp"
@@ -37,7 +50,9 @@
3750
#include <condition_variable>
3851
#include <cstdint>
3952
#include <exception>
53+
#include <limits>
4054
#include <mutex>
55+
#include <random>
4156
#include <span>
4257
#include <thread>
4358
#include <type_traits>
@@ -690,12 +705,12 @@ namespace experimental::execution
690705

691706
alignas(64) __std::atomic<std::uint32_t> num_active_{};
692707
alignas(64) remote_queue_list remotes_;
693-
std::uint32_t thread_count_;
694-
std::uint32_t max_steals_{thread_count_ + 1};
695-
bwos_params params_;
696-
std::vector<std::thread> threads_;
697-
std::vector<std::optional<thread_state>> thread_states_;
698-
numa_policy numa_;
708+
std::uint32_t thread_count_;
709+
std::uint32_t max_steals_{thread_count_ + 1};
710+
bwos_params params_;
711+
std::vector<std::thread> threads_;
712+
std::vector<__optional<thread_state>> thread_states_;
713+
numa_policy numa_;
699714

700715
struct thread_index_by_numa_node
701716
{
@@ -1416,12 +1431,10 @@ namespace experimental::execution
14161431
}
14171432
};
14181433

1419-
using variant_t = __value_types_of_t<CvSender,
1420-
env_of_t<Receiver>,
1421-
__q<__decayed_std_tuple>,
1422-
__q<__nullable_std_variant>>;
1434+
using variant_t =
1435+
__value_types_of_t<CvSender, env_of_t<Receiver>, __q<__decayed_tuple>, __q<__variant>>;
14231436

1424-
variant_t data_;
1437+
variant_t data_{STDEXEC::__no_init};
14251438
_static_thread_pool& pool_;
14261439
Receiver rcvr_;
14271440
Shape shape_;
@@ -1440,7 +1453,7 @@ namespace experimental::execution
14401453
if constexpr (Parallelize)
14411454
{
14421455
return static_cast<std::uint32_t>(
1443-
(std::min) (shape_, static_cast<Shape>(pool_.available_parallelism())));
1456+
__umin({std::size_t(shape_), std::size_t(pool_.available_parallelism())}));
14441457
}
14451458
else
14461459
{
@@ -1451,19 +1464,8 @@ namespace experimental::execution
14511464
template <class F>
14521465
void apply(F f)
14531466
{
1454-
std::visit(
1455-
[&]<class Tuple>(Tuple& tupl) -> void
1456-
{
1457-
if constexpr (__std::same_as<Tuple, std::monostate>)
1458-
{
1459-
STDEXEC_TERMINATE();
1460-
}
1461-
else
1462-
{
1463-
std::apply([&](auto&... args) -> void { f(args...); }, tupl);
1464-
}
1465-
},
1466-
data_);
1467+
STDEXEC_ASSERT(!data_.__is_valueless());
1468+
__visit([&](auto& tupl) -> void { __apply(std::move(f), tupl); }, data_);
14671469
}
14681470

14691471
//! Construct from a pool, receiver, shape, and function.
@@ -1501,7 +1503,7 @@ namespace experimental::execution
15011503
template <class... As>
15021504
void set_value(As&&... as) noexcept
15031505
{
1504-
using tuple_t = __decayed_std_tuple<As...>;
1506+
using tuple_t = __decayed_tuple<As...>;
15051507

15061508
shared_state& state = shared_state_;
15071509

@@ -1514,6 +1516,7 @@ namespace experimental::execution
15141516
if constexpr (MayThrow)
15151517
{
15161518
STDEXEC::set_error(std::move(state.rcvr_), std::current_exception());
1519+
return;
15171520
}
15181521
}
15191522

@@ -1523,7 +1526,7 @@ namespace experimental::execution
15231526
}
15241527
else
15251528
{
1526-
state.apply([&](auto&... args)
1529+
state.apply([&](auto&... args) noexcept -> void
15271530
{ STDEXEC::set_value(std::move(state.rcvr_), std::move(args)...); });
15281531
}
15291532
}
@@ -1761,7 +1764,7 @@ namespace experimental::execution
17611764
std::size_t nthreads = this->pool_.available_parallelism();
17621765
bwos_params params = this->pool_.params();
17631766
std::size_t local_size = params.blockSize * params.numBlocks;
1764-
std::size_t chunk_size = (std::min) (size / nthreads, local_size * nthreads);
1767+
std::size_t chunk_size = __umin({size / nthreads, local_size * nthreads});
17651768
auto& remote_queue = *this->pool_.get_remote_queue();
17661769
auto it = std::ranges::begin(this->range_);
17671770
std::size_t i0 = 0;

include/exec/thread_pool_base.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,28 @@
1717
*/
1818
#pragma once
1919

20+
#include "../stdexec/__detail/__execution_fwd.hpp"
21+
22+
#include "../stdexec/__detail/__connect.hpp"
23+
#include "../stdexec/__detail/__env.hpp"
24+
#include "../stdexec/__detail/__meta.hpp"
25+
#include "../stdexec/__detail/__operation_states.hpp"
26+
#include "../stdexec/__detail/__receivers.hpp"
27+
#include "../stdexec/__detail/__schedulers.hpp"
28+
#include "../stdexec/__detail/__transform_completion_signatures.hpp"
29+
#include "../stdexec/__detail/__type_traits.hpp"
30+
2031
#include "sender_for.hpp"
2132
#include "static_thread_pool.hpp"
2233

34+
#include <atomic>
35+
#include <concepts>
36+
#include <cstdint>
37+
#include <exception>
38+
#include <tuple>
39+
#include <utility>
40+
#include <variant>
41+
2342
namespace experimental::execution
2443
{
2544
struct CANNOT_DISPATCH_BULK_ALGORITHM_TO_THE_POOL_SCHEDULER;

include/exec/trampoline_scheduler.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
*/
1717
#pragma once
1818

19-
#include "../stdexec/execution.hpp"
19+
#include "../stdexec/__detail/__execution_fwd.hpp"
20+
21+
#include "../stdexec/__detail/__concepts.hpp"
22+
#include "../stdexec/__detail/__domain.hpp"
23+
#include "../stdexec/__detail/__env.hpp"
24+
#include "../stdexec/__detail/__receivers.hpp"
25+
#include "../stdexec/stop_token.hpp"
26+
2027
#include "completion_behavior.hpp"
2128

2229
#include <cstddef>

include/stdexec/__detail/__execution_fwd.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
#pragma once
1717

18-
#include "__concepts.hpp"
1918
#include "__config.hpp" // IWYU pragma: export
19+
20+
#include "__concepts.hpp"
2021
#include "__meta.hpp"
2122
#include "__type_traits.hpp"
2223
#include "__utility.hpp"

0 commit comments

Comments
 (0)