Commit 40013796 authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

io/uring/Operation: add method ReplaceUring()

parent 382273ab
......@@ -67,6 +67,16 @@ public:
// TODO: io_uring_prep_cancel()
}
void Replace(Operation &old_operation,
Operation &new_operation) noexcept {
assert(operation == &old_operation);
assert(old_operation.cancellable == this);
old_operation.cancellable = nullptr;
operation = &new_operation;
new_operation.cancellable = this;
}
void OnUringCompletion(int res) noexcept {
if (operation == nullptr)
return;
......
......@@ -33,6 +33,7 @@
#include "Operation.hxx"
#include "CancellableOperation.hxx"
#include <cassert>
#include <utility>
namespace Uring {
......@@ -46,4 +47,14 @@ Operation::CancelUring() noexcept
std::exchange(cancellable, nullptr)->Cancel(*this);
}
void
Operation::ReplaceUring(Operation &new_operation) noexcept
{
assert(IsUringPending());
cancellable->Replace(*this, new_operation);
assert(cancellable == nullptr);
}
} // namespace Uring
......@@ -63,6 +63,12 @@ public:
void CancelUring() noexcept;
/**
* Replace this pending operation with a new one. This method
* is only legal if IsUringPending().
*/
void ReplaceUring(Operation &new_operation) noexcept;
/**
* This method is called when the operation completes.
*
* @param res the result code; the meaning is specific to the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment