Clean up and deduplicate parts of __io_uring_flush_sq(), also helping to generate a better binary if a compiler is not smart enough. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- src/queue.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/queue.c b/src/queue.c index ce5d237..2f0f19b 100644 --- a/src/queue.c +++ b/src/queue.c @@ -198,23 +198,20 @@ int __io_uring_flush_sq(struct io_uring *ring) { struct io_uring_sq *sq = &ring->sq; const unsigned mask = *sq->kring_mask; - unsigned ktail, to_submit; + unsigned ktail = *sq->ktail; + unsigned to_submit = sq->sqe_tail - sq->sqe_head; - if (sq->sqe_head == sq->sqe_tail) { - ktail = *sq->ktail; + if (!to_submit) goto out; - } /* * Fill in sqes that we have queued up, adding them to the kernel ring */ - ktail = *sq->ktail; - to_submit = sq->sqe_tail - sq->sqe_head; - while (to_submit--) { + do { sq->array[ktail & mask] = sq->sqe_head & mask; ktail++; sq->sqe_head++; - } + } while (--to_submit); /* * Ensure that the kernel sees the SQE updates before it sees the tail -- 2.31.1