diff options
author | Max Kellermann <mk@cm4all.com> | 2020-09-10 15:32:56 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-09-22 21:50:48 +0200 |
commit | 4001379663d9e5ba249723e752efa74253e9a793 (patch) | |
tree | c5c3df6e99d45d4c8c7702a5c8098d9e1438a5bd /src/io | |
parent | 382273abc53542de0e58ef47db1ab4634d09ea2f (diff) |
io/uring/Operation: add method ReplaceUring()
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/uring/CancellableOperation.hxx | 10 | ||||
-rw-r--r-- | src/io/uring/Operation.cxx | 11 | ||||
-rw-r--r-- | src/io/uring/Operation.hxx | 6 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/io/uring/CancellableOperation.hxx b/src/io/uring/CancellableOperation.hxx index b55af5867..e7b71958c 100644 --- a/src/io/uring/CancellableOperation.hxx +++ b/src/io/uring/CancellableOperation.hxx @@ -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; diff --git a/src/io/uring/Operation.cxx b/src/io/uring/Operation.cxx index 120434e97..8fadebcf4 100644 --- a/src/io/uring/Operation.cxx +++ b/src/io/uring/Operation.cxx @@ -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 diff --git a/src/io/uring/Operation.hxx b/src/io/uring/Operation.hxx index 8f753b16f..a8c3b4adc 100644 --- a/src/io/uring/Operation.hxx +++ b/src/io/uring/Operation.hxx @@ -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 |