Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jan 26, 2025
1 parent 109ac12 commit deb5566
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions include/ylt/coro_io/coro_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ constexpr int finish_cancel_flag = 3;
template <typename ret_type, typename IO_func, typename io_object>
inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
io_object &obj) noexcept {

callback_awaitor<ret_type> awaitor;
auto slot = co_await async_simple::coro::CurrentSlot{};
if (!slot) {
Expand All @@ -248,13 +247,16 @@ inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
[&obj, lock](async_simple::SignalType signalType,
async_simple::Signal *signal) {
int expected = detail::no_cancel_flag;
if (!lock->compare_exchange_strong(expected, detail::could_cancel_flag,
if (!lock->compare_exchange_strong(expected,
detail::could_cancel_flag,
std::memory_order_acq_rel)) {
if (expected == detail::could_cancel_flag) {
if (lock->compare_exchange_strong(expected, detail::start_cancel_flag,
if (lock->compare_exchange_strong(expected,
detail::start_cancel_flag,
std::memory_order_release)) {
detail::cancel(obj);
lock->store(detail::finish_cancel_flag, std::memory_order_release);
lock->store(detail::finish_cancel_flag,
std::memory_order_release);
}
}
}
Expand All @@ -276,10 +278,12 @@ inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
if (!lock->compare_exchange_strong(expected, detail::could_cancel_flag,
std::memory_order_acq_rel)) {
if (expected == detail::could_cancel_flag) {
if (lock->compare_exchange_strong(expected, detail::start_cancel_flag,
if (lock->compare_exchange_strong(expected,
detail::start_cancel_flag,
std::memory_order_release)) {
detail::cancel(obj);
lock->store(detail::finish_cancel_flag, std::memory_order_release);
lock->store(detail::finish_cancel_flag,
std::memory_order_release);
}
}
}
Expand All @@ -292,16 +296,17 @@ inline async_simple::coro::Lazy<ret_type> async_io(IO_func io_func,
if (expected != detail::finish_cancel_flag) {
do {
if (expected == detail::could_cancel_flag) {
if (lock->compare_exchange_strong(expected, detail::finish_cancel_flag,
if (lock->compare_exchange_strong(expected,
detail::finish_cancel_flag,
std::memory_order_acq_rel) ||
expected == detail::finish_cancel_flag) {
break;
}
}
// flag is start_cancel_flag now.
// wait cancel finish to make sure io object's life-time
for (;
lock->load(std::memory_order_acquire) == detail::start_cancel_flag;) {
for (; lock->load(std::memory_order_acquire) ==
detail::start_cancel_flag;) {
co_await coro_io::post(
[]() {
},
Expand Down

0 comments on commit deb5566

Please sign in to comment.