blob: 4f6e8e6a703b573e8f5c0d3e24fa397e090008e2 [file] [log] [blame]
Jens Axboe2ae0b202013-05-28 14:16:55 +02001#ifndef FIO_IO_U_QUEUE
2#define FIO_IO_U_QUEUE
3
4#include <assert.h>
5
6struct io_u;
7
8struct io_u_queue {
9 struct io_u **io_us;
10 unsigned int nr;
11};
12
13static inline struct io_u *io_u_qpop(struct io_u_queue *q)
14{
15 if (q->nr)
16 return q->io_us[--q->nr];
17
18 return NULL;
19}
20
21static inline void io_u_qpush(struct io_u_queue *q, struct io_u *io_u)
22{
23 q->io_us[q->nr++] = io_u;
24}
25
26static inline int io_u_qempty(struct io_u_queue *q)
27{
28 return !q->nr;
29}
30
31#define io_u_qiter(q, io_u, i) \
32 for (i = 0, io_u = (q)->io_us[0]; i < (q)->nr; i++, io_u = (q)->io_us[i])
33
34int io_u_qinit(struct io_u_queue *q, unsigned int nr);
35void io_u_qexit(struct io_u_queue *q);
36
37struct io_u_ring {
38 unsigned int head;
39 unsigned int tail;
40 unsigned int max;
41 struct io_u **ring;
42};
43
44int io_u_rinit(struct io_u_ring *ring, unsigned int nr);
45void io_u_rexit(struct io_u_ring *ring);
46
47static inline void io_u_rpush(struct io_u_ring *r, struct io_u *io_u)
48{
49 if (r->head + 1 != r->tail) {
50 r->ring[r->head] = io_u;
51 r->head = (r->head + 1) & (r->max - 1);
52 return;
53 }
54
55 assert(0);
56}
57
58static inline struct io_u *io_u_rpop(struct io_u_ring *r)
59{
60 if (r->head != r->tail) {
61 struct io_u *io_u = r->ring[r->tail];
62
63 r->tail = (r->tail + 1) & (r->max - 1);
64 return io_u;
65 }
66
67 return NULL;
68}
69
70static inline int io_u_rempty(struct io_u_ring *ring)
71{
72 return ring->head == ring->tail;
73}
74
75#endif