X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=io_u_queue.h;h=bda40d5ea263920055f6d75c62bdca8e4559034c;hb=aad918e47d119eb2043311f1a2a45ce109c047d1;hp=4f6e8e6a703b573e8f5c0d3e24fa397e090008e2;hpb=2ae0b204743d6b4048c6fffd46c6280a70f2ecd1;p=fio.git diff --git a/io_u_queue.h b/io_u_queue.h index 4f6e8e6a..bda40d5e 100644 --- a/io_u_queue.h +++ b/io_u_queue.h @@ -12,8 +12,13 @@ struct io_u_queue { static inline struct io_u *io_u_qpop(struct io_u_queue *q) { - if (q->nr) - return q->io_us[--q->nr]; + if (q->nr) { + const unsigned int next = --q->nr; + struct io_u *io_u = q->io_us[next]; + + q->io_us[next] = NULL; + return io_u; + } return NULL; } @@ -23,13 +28,13 @@ static inline void io_u_qpush(struct io_u_queue *q, struct io_u *io_u) q->io_us[q->nr++] = io_u; } -static inline int io_u_qempty(struct io_u_queue *q) +static inline int io_u_qempty(const struct io_u_queue *q) { return !q->nr; } #define io_u_qiter(q, io_u, i) \ - for (i = 0, io_u = (q)->io_us[0]; i < (q)->nr; i++, io_u = (q)->io_us[i]) + for (i = 0; i < (q)->nr && (io_u = (q)->io_us[i]); i++) int io_u_qinit(struct io_u_queue *q, unsigned int nr); void io_u_qexit(struct io_u_queue *q);