queue: clean up SQ flushing
Clean up and deduplicate parts of __io_uring_flush_sq(), also helping to
generate a better binary if a compiler is not smart enough.
@@ -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
