Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions include/condy/detail/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,6 @@ inline int sync_msg_ring(io_uring_sqe *sqe_data) noexcept {
#endif
}

class CancelRequest {
public:
CancelRequest(uintptr_t data) : data_(data) {}

void wait() noexcept {
while (!finished_.load(std::memory_order_acquire)) {
finished_.wait(false, std::memory_order_relaxed);
}
}

void notify() noexcept {
finished_.store(true, std::memory_order_release);
finished_.notify_one();
}

uintptr_t data() const noexcept { return data_; }

private:
uintptr_t data_;
std::atomic_bool finished_ = false;
};

class OpFinishHandleBase {
public:
using HandleFunc = bool (*)(void *, io_uring_cqe *) noexcept;
Expand Down
18 changes: 4 additions & 14 deletions include/condy/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,13 @@ class Runtime {
return;
}

detail::CancelRequest request(data);
detail::tsan_release(&request);
schedule_msg_ring_(
curr_runtime,
detail::encode_work(&request, detail::WorkType::Cancel));
// Potential address reuse problem?
schedule_msg_ring_(curr_runtime, detail::encode_work_ptr(
data, detail::WorkType::Cancel));
if (curr_runtime != nullptr) {
// Ensure the cancel msg is submitted.
curr_runtime->ring_.submit();
}
// Block until the runtime thread has submitted the cancel SQE. This is
// important to prevent address reuse of the same data pointer, which
// can lead to incorrect cancellation or other bugs.
request.wait();
}

void pend_work_internal() noexcept {
Expand Down Expand Up @@ -403,12 +397,8 @@ class Runtime {
(*work)();
}
} else if (type == detail::WorkType::Cancel) {
detail::CancelRequest *request =
static_cast<detail::CancelRequest *>(data);
detail::tsan_acquire(request);
io_uring_sqe *sqe = ring_.get_sqe();
prep_cancel_(sqe, request->data());
request->notify();
prep_cancel_(sqe, reinterpret_cast<uintptr_t>(data));
} else if (type == detail::WorkType::Common) {
auto *handle = static_cast<detail::OpFinishHandleBase *>(data);
auto op_finish = handle->handle(cqe);
Expand Down
Loading