Skip to content

Commit ab5ab2e

Browse files
authored
fix futureAwaiter test failed in aarch64 (#433)
1 parent be40b16 commit ab5ab2e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

async_simple/coro/FutureAwaiter.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ struct FutureAwaiter {
4444
future_ = makeReadyFuture<T>(
4545
std::make_exception_ptr(async_simple::SignalException(
4646
SignalType::Terminate,
47-
"FutureAwaiter is only allowed to be called by Lazy")));
47+
"FutureAwaiter is cancelled by signal")));
48+
// Add thread fence, make sure future_ has being assigned before
49+
// continuation or cancellation in arm.
50+
std::atomic_thread_fence(std::memory_order_acq_rel);
4851
auto state = std::make_shared<std::atomic<bool>>(true);
49-
5052
if (!signalHelper{Terminate}.tryEmplace(
5153
cancellationSlot,
5254
[continuation, ex, ctx, state](auto&&...) mutable {
@@ -116,8 +118,9 @@ auto operator co_await(Future<T>&& future) {
116118
}
117119

118120
template <typename T>
119-
[[deprecated("Require an rvalue future.")]]
120-
auto operator co_await(T&& future) requires IsFuture<std::decay_t<T>>::value {
121+
[[deprecated("Require an rvalue future.")]] auto operator co_await(T&& future)
122+
requires IsFuture<std::decay_t<T>>::value
123+
{
121124
return std::move(operator co_await(std::move(future)));
122125
}
123126

async_simple/coro/test/FutureAwaiterTest.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ TEST_F(FutureAwaiterTest, testWithFuture) {
7979
syncAwait(lazy3().via(&ex2));
8080
}
8181

82-
// The test fails in debug mode with internal CI. Disable it to keep the CI green.
83-
#if 0
8482
TEST_F(FutureAwaiterTest, testWithFutureCancel) {
8583
async_simple::executors::SimpleExecutor ex1(2);
8684
auto lazy = [&]() -> Lazy<> {
@@ -109,15 +107,15 @@ TEST_F(FutureAwaiterTest, testWithFutureCancel) {
109107
int ret = 0;
110108
try {
111109
ret = co_await std::move(fut);
112-
} catch (...) {
110+
} catch (const std::exception& e) {
111+
std::cout << e.what() << std::endl;
113112
}
114113
EXPECT_EQ(ret, 2);
115114
};
116115
syncAwait(collectAll<async_simple::Terminate>(
117116
lazy2().via(&ex1),
118117
async_simple::coro::sleep(std::chrono::seconds::max()).via(&ex1)));
119118
}
120-
#endif
121119

122120
namespace detail {
123121

0 commit comments

Comments
 (0)