server: bump version
[fio.git] / io_u_queue.c
CommitLineData
2ae0b204
JA
1#include <stdlib.h>
2#include "io_u_queue.h"
3
4int io_u_qinit(struct io_u_queue *q, unsigned int nr)
5{
572cfb3f 6 q->io_us = calloc(nr, sizeof(struct io_u *));
2ae0b204
JA
7 if (!q->io_us)
8 return 1;
9
10 q->nr = 0;
6fb1bda0 11 q->max = nr;
2ae0b204
JA
12 return 0;
13}
14
15void io_u_qexit(struct io_u_queue *q)
16{
17 free(q->io_us);
18}
19
20int io_u_rinit(struct io_u_ring *ring, unsigned int nr)
21{
22 ring->max = nr + 1;
23 if (ring->max & (ring->max - 1)) {
24 ring->max--;
25 ring->max |= ring->max >> 1;
26 ring->max |= ring->max >> 2;
27 ring->max |= ring->max >> 4;
28 ring->max |= ring->max >> 8;
29 ring->max |= ring->max >> 16;
30 ring->max++;
31 }
32
572cfb3f 33 ring->ring = calloc(ring->max, sizeof(struct io_u *));
2ae0b204
JA
34 if (!ring->ring)
35 return 1;
36
37 ring->head = ring->tail = 0;
38 return 0;
39}
40
41void io_u_rexit(struct io_u_ring *ring)
42{
43 free(ring->ring);
44}