client: use temp buffer for single output flush for json/disk util
[fio.git] / io_u_queue.c
CommitLineData
2ae0b204
JA
1#include <stdlib.h>
2#include "io_u_queue.h"
3
34851ad5 4bool io_u_qinit(struct io_u_queue *q, unsigned int nr)
2ae0b204 5{
572cfb3f 6 q->io_us = calloc(nr, sizeof(struct io_u *));
2ae0b204 7 if (!q->io_us)
34851ad5 8 return false;
2ae0b204
JA
9
10 q->nr = 0;
6fb1bda0 11 q->max = nr;
34851ad5 12 return true;
2ae0b204
JA
13}
14
15void io_u_qexit(struct io_u_queue *q)
16{
17 free(q->io_us);
18}
19
34851ad5 20bool io_u_rinit(struct io_u_ring *ring, unsigned int nr)
2ae0b204
JA
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 34 if (!ring->ring)
34851ad5 35 return false;
2ae0b204
JA
36
37 ring->head = ring->tail = 0;
34851ad5 38 return true;
2ae0b204
JA
39}
40
41void io_u_rexit(struct io_u_ring *ring)
42{
43 free(ring->ring);
44}