File: io_u_queue.h

package info (click to toggle)
fio 2.1.11-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,712 kB
  • ctags: 5,643
  • sloc: ansic: 44,396; sh: 1,489; python: 400; makefile: 342
file content (75 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef FIO_IO_U_QUEUE
#define FIO_IO_U_QUEUE

#include <assert.h>

struct io_u;

struct io_u_queue {
	struct io_u **io_us;
	unsigned int nr;
};

static inline struct io_u *io_u_qpop(struct io_u_queue *q)
{
	if (q->nr)
		return q->io_us[--q->nr];

	return NULL;
}

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)
{
	return !q->nr;
}

#define io_u_qiter(q, io_u, 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);

struct io_u_ring {
	unsigned int head;
	unsigned int tail;
	unsigned int max;
	struct io_u **ring;
};

int io_u_rinit(struct io_u_ring *ring, unsigned int nr);
void io_u_rexit(struct io_u_ring *ring);

static inline void io_u_rpush(struct io_u_ring *r, struct io_u *io_u)
{
	if (r->head + 1 != r->tail) {
		r->ring[r->head] = io_u;
		r->head = (r->head + 1) & (r->max - 1);
		return;
	}

	assert(0);
}

static inline struct io_u *io_u_rpop(struct io_u_ring *r)
{
	if (r->head != r->tail) {
		struct io_u *io_u = r->ring[r->tail];

		r->tail = (r->tail + 1) & (r->max - 1);
		return io_u;
	}

	return NULL;
}

static inline int io_u_rempty(struct io_u_ring *ring)
{
	return ring->head == ring->tail;
}

#endif