io/uring/Operation: add method ReplaceUring()

This commit is contained in:
Max Kellermann 2020-09-10 15:32:56 +02:00 committed by Max Kellermann
parent 382273abc5
commit 4001379663
3 changed files with 27 additions and 0 deletions

View File

@ -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;

View File

@ -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

View File

@ -62,6 +62,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.
*