Skip to content

Commit c5ee582

Browse files
ericnieblerispeters
authored andcommitted
use portable atomics, address linter warnings
1 parent f600a55 commit c5ee582

File tree

9 files changed

+152
-140
lines changed

9 files changed

+152
-140
lines changed

include/stdexec/__detail/__counting_scopes.hpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818

1919
#include "__execution_fwd.hpp"
2020

21+
#include "__atomic.hpp"
2122
#include "__concepts.hpp"
2223
#include "__env.hpp"
2324
#include "__receivers.hpp"
2425
#include "__schedulers.hpp"
2526
#include "__senders_core.hpp"
26-
#include "__sender_introspection.hpp"
2727
#include "__stop_when.hpp"
28-
#include "__type_traits.hpp"
2928
#include "../stop_token.hpp"
3029

31-
#include <atomic>
3230
#include <cstddef>
3331
#include <exception>
3432
#include <limits>
@@ -103,15 +101,16 @@ namespace stdexec {
103101
stdexec::set_value(std::move(__rcvr_));
104102
}
105103

106-
template <class E>
107-
void set_error(E&& e) && noexcept {
108-
stdexec::set_error(std::move(__rcvr_), static_cast<E&&>(e));
104+
template <class _Error>
105+
void set_error(_Error&& __err) && noexcept {
106+
stdexec::set_error(std::move(__rcvr_), static_cast<_Error&&>(__err));
109107
};
110108

111109
void set_stopped() && noexcept {
112110
stdexec::set_stopped(std::move(__rcvr_));
113111
}
114112

113+
[[nodiscard]]
115114
decltype(auto) get_env() const noexcept {
116115
return stdexec::get_env(__rcvr_);
117116
}
@@ -124,7 +123,7 @@ namespace stdexec {
124123
_Rcvr& __receiver_;
125124
__op_t __op_;
126125

127-
__join_state(__base_scope* __scope, _Rcvr& __rcvr)
126+
explicit __join_state(__base_scope* __scope, _Rcvr& __rcvr)
128127
noexcept(__nothrow_callable<connect_t, __sched_sender, __rcvr_t>)
129128
: __join_state_base(
130129
__scope,
@@ -181,6 +180,7 @@ namespace stdexec {
181180
return __scope_ != nullptr;
182181
}
183182

183+
[[nodiscard]]
184184
__association_t try_associate() const noexcept {
185185
// [exec.counting.scopes.general] paragraph 5.3
186186
if (__scope_) {
@@ -240,7 +240,7 @@ namespace stdexec {
240240
// with all the now-completed associated operations but the scope may be destroyed
241241
// on yet another thread so we ought to execute a load-acquire to ensure the
242242
// current thread has properly synchronized.
243-
auto bits = __bits_.load(std::memory_order_acquire);
243+
auto bits = __bits_.load(__std::memory_order_acquire);
244244
if (!__destructible(bits)) {
245245
std::terminate();
246246
}
@@ -262,7 +262,7 @@ namespace stdexec {
262262
// any subsequent calls to __try_associate that must fail as a result of
263263
// this closure; we don't use acquire-release semantics because the caller
264264
// is *sending* a signal, not receiving one
265-
__bits_.fetch_or(__closed, std::memory_order_release);
265+
__bits_.fetch_or(__closed, __std::memory_order_release);
266266
}
267267

268268
bool __try_associate() noexcept {
@@ -288,7 +288,7 @@ namespace stdexec {
288288
// we might be about to observe that the scope has been closed; we should
289289
// establish that the closure happened-before this attempt to associate
290290
// so this needs to be a load-acquire
291-
auto oldBits = __bits_.load(std::memory_order_acquire);
291+
auto oldBits = __bits_.load(__std::memory_order_acquire);
292292
std::size_t newBits; //intentionally uninitialized
293293

294294
do {
@@ -315,7 +315,7 @@ namespace stdexec {
315315
// with the thread that closed the scope if we happen to observe that; it's
316316
// UB for the on-failure ordering to be weaker than the on-success ordering
317317
// so we have to use acquire for both.
318-
std::memory_order_acquire));
318+
__std::memory_order_acquire));
319319

320320
// [exec.simple.counting.mem] paragraph 6
321321
// Returns: If count was incremented, an object of type assoc-t that is engaged
@@ -363,7 +363,7 @@ namespace stdexec {
363363

364364
// relaxed is sufficient here because the CAS loop we're about to run won't
365365
// complete until we've synchronized with acquire-release semantics
366-
auto oldBits = __bits_.load(std::memory_order_relaxed);
366+
auto oldBits = __bits_.load(__std::memory_order_relaxed);
367367
std::size_t newBits; // intentionally uninitialized
368368

369369
// [exec.simple.counting.mem] paragraph 7
@@ -379,10 +379,10 @@ namespace stdexec {
379379
// of the just-finished operation to other scope users, and we also need
380380
// load-acquire semantics in case we're the last associated operation to
381381
// complete and thus initiate the tear-down of the scope
382-
std::memory_order_acq_rel,
382+
__std::memory_order_acq_rel,
383383
// on failure, we're going to immediately try to synchronize again so we
384384
// can get away with relaxed semantics
385-
std::memory_order_relaxed));
385+
__std::memory_order_relaxed));
386386

387387
if (__is_joined(newBits)) {
388388
// [exec.simple.counting.mem] paragraph 8 continued...
@@ -397,7 +397,7 @@ namespace stdexec {
397397
bool __start_join_sender(__counting_scopes::__join_state_base& __joinOp) noexcept {
398398
// relaxed is sufficient because the CAS loop below will continue until
399399
// we've synchronized
400-
auto oldBits = __bits_.load(std::memory_order_relaxed);
400+
auto oldBits = __bits_.load(__std::memory_order_relaxed);
401401

402402
do {
403403
// [exec.simple.counting.mem] para (9.1)
@@ -419,10 +419,10 @@ namespace stdexec {
419419
// that the scope is closed and consume from all the now-completed
420420
// associated operations any updates they made so we need
421421
// acquire-release semantics
422-
std::memory_order_acq_rel,
422+
__std::memory_order_acq_rel,
423423
// on failure, relaxed is fine because we'll loop back and try
424424
// again to synchronize
425-
std::memory_order_relaxed)) {
425+
__std::memory_order_relaxed)) {
426426
return true;
427427
}
428428
}
@@ -450,7 +450,7 @@ namespace stdexec {
450450
// completion of any join operation.
451451
//
452452
// on failure, relaxed is sufficient because we'll loop around and try again
453-
std::memory_order_relaxed)) {
453+
__std::memory_order_relaxed)) {
454454
return !__register(__joinOp);
455455
}
456456
}
@@ -474,7 +474,7 @@ namespace stdexec {
474474
// joined = zero | __closed
475475
//
476476
// INVARIANT: __bits_ = (count << 3) | (state & 7)
477-
std::atomic<std::size_t> __bits_{0ul};
477+
__std::atomic<std::size_t> __bits_{0ul};
478478

479479
// An intrusive singly-linked list of join-sender operation states;
480480
// elements of the list have been "registered" to be completed when the
@@ -484,7 +484,7 @@ namespace stdexec {
484484
// indicates that the last associated operation has been disassociated
485485
// and any previously-registered join operations have been (or are about
486486
// to be) completed.
487-
std::atomic<void*> __registeredJoinOps_{nullptr};
487+
__std::atomic<void*> __registeredJoinOps_{nullptr};
488488

489489
// returns true in the unused and unused-and-closed states; since the bit
490490
// pattern for joined matches the unused-and-closed bit pattern, returns
@@ -561,7 +561,7 @@ namespace stdexec {
561561
// observe that the last decrement has already happened; in that case, we need to
562562
// establish that all of the now-completed associated operations happen-before the
563563
// completion of this join operation
564-
auto* head = __registeredJoinOps_.load(std::memory_order_acquire);
564+
auto* head = __registeredJoinOps_.load(__std::memory_order_acquire);
565565

566566
do {
567567
if (head == this) {
@@ -583,10 +583,10 @@ namespace stdexec {
583583
// of registered operations with acquire semantics; however, the on-success
584584
// ordering has to be at least as strong as the on-failure ordering, for
585585
// which we need acquire semantics, so on-success has to be acquire-release.
586-
std::memory_order_acq_rel,
586+
__std::memory_order_acq_rel,
587587
// on failure, we need acquire semantics in case we're about to observe the
588588
// sentinel value and return early without trying again
589-
std::memory_order_acquire));
589+
__std::memory_order_acquire));
590590

591591
return true;
592592
}
@@ -602,7 +602,7 @@ namespace stdexec {
602602
// need release semantics to ensure that any future join-senders that
603603
// observe the sentinel value perform that observation with a happens-after
604604
// relationship with the current update
605-
void* waitingOps = __registeredJoinOps_.exchange(this, std::memory_order_acq_rel);
605+
void* waitingOps = __registeredJoinOps_.exchange(this, __std::memory_order_acq_rel);
606606

607607
// at this point, waitingOps had better be either nullptr or the address
608608
// of a join operation waiting to be completed; otherwise, the upcoming
@@ -638,11 +638,13 @@ namespace stdexec {
638638
// [exec.simple.counting.token]
639639
struct token {
640640
template <sender _Sender>
641+
[[nodiscard]]
641642
_Sender&& wrap(_Sender&& __snd) const noexcept {
642643
// [exec.simple.counting.token] paragraph 1
643644
return static_cast<_Sender&&>(__snd);
644645
}
645646

647+
[[nodiscard]]
646648
__assoc_t try_associate() const noexcept {
647649
// [exec.simple.counting.token] paragraph 2
648650
return __scope_->__try_associate();
@@ -660,6 +662,7 @@ namespace stdexec {
660662

661663
using __counting_scopes::__base_scope::max_associations;
662664

665+
[[nodiscard]]
663666
token get_token() noexcept {
664667
// [exec.simple.counting.mem] paragraph 1
665668
return token{this};
@@ -668,6 +671,7 @@ namespace stdexec {
668671
// [exec.simple.counting.mem] paragraphs 2 and 3
669672
using __counting_scopes::__base_scope::close;
670673

674+
[[nodiscard]]
671675
sender auto join() noexcept {
672676
// [exec.simple.counting.mem] paragraph 4
673677
return __make_sexpr<__counting_scopes::__scope_join_t>(this);
@@ -697,12 +701,14 @@ namespace stdexec {
697701

698702
struct token {
699703
template <sender _Sender>
704+
[[nodiscard]]
700705
sender auto wrap(_Sender&& __snd) const
701706
noexcept(__nothrow_constructible_from<std::remove_cvref_t<_Sender>, _Sender>) {
702707
// [exec.scope.counting] paragraph 7
703708
return __stop_when(static_cast<_Sender&&>(__snd), __scope_->__stopSource_.get_token());
704709
}
705710

711+
[[nodiscard]]
706712
__assoc_t try_associate() const noexcept {
707713
// [exec.scope.counting] paragraph 8
708714
return __scope_->__try_associate();
@@ -720,13 +726,15 @@ namespace stdexec {
720726

721727
using __counting_scopes::__base_scope::max_associations;
722728

729+
[[nodiscard]]
723730
token get_token() noexcept {
724731
// [exec.scope.counting] paragraph 2
725732
return token{this};
726733
}
727734

728735
using __counting_scopes::__base_scope::close;
729736

737+
[[nodiscard]]
730738
sender auto join() noexcept {
731739
return __make_sexpr<__counting_scopes::__scope_join_t>(this);
732740
}

include/stdexec/__detail/__scope_concepts.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "__completion_signatures.hpp"
2222
#include "__concepts.hpp"
23-
#include "__env.hpp"
2423
#include "__operation_states.hpp"
2524
#include "__receivers.hpp"
2625
#include "__senders_core.hpp"

include/stdexec/__detail/__spawn.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
#include "__execution_fwd.hpp"
2020

21-
#include "__concepts.hpp"
2221
#include "__env.hpp"
23-
#include "__queries.hpp"
2422
#include "__receivers.hpp"
2523
#include "__scope_concepts.hpp"
2624
#include "__senders_core.hpp"

0 commit comments

Comments
 (0)