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: ...@@ -67,6 +67,16 @@ public:
// TODO: io_uring_prep_cancel() // 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 { void OnUringCompletion(int res) noexcept {
if (operation == nullptr) if (operation == nullptr)
return; return;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "Operation.hxx" #include "Operation.hxx"
#include "CancellableOperation.hxx" #include "CancellableOperation.hxx"
#include <cassert>
#include <utility> #include <utility>
namespace Uring { namespace Uring {
...@@ -46,4 +47,14 @@ Operation::CancelUring() noexcept ...@@ -46,4 +47,14 @@ Operation::CancelUring() noexcept
std::exchange(cancellable, nullptr)->Cancel(*this); 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 } // namespace Uring
...@@ -63,6 +63,12 @@ public: ...@@ -63,6 +63,12 @@ public:
void CancelUring() noexcept; 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. * This method is called when the operation completes.
* *
* @param res the result code; the meaning is specific to the * @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