client: add a newline after terse disk util
[fio.git] / io_u_queue.c
CommitLineData
2ae0b204 1#include <stdlib.h>
3114b675 2#include <string.h>
2ae0b204 3#include "io_u_queue.h"
3114b675 4#include "smalloc.h"
2ae0b204 5
3114b675 6bool io_u_qinit(struct io_u_queue *q, unsigned int nr, bool shared)
2ae0b204 7{
3114b675
VF
8 if (shared)
9 q->io_us = smalloc(nr * sizeof(struct io_u *));
10 else
11 q->io_us = calloc(nr, sizeof(struct io_u *));
12
2ae0b204 13 if (!q->io_us)
34851ad5 14 return false;
2ae0b204
JA
15
16 q->nr = 0;
6fb1bda0 17 q->max = nr;
34851ad5 18 return true;
2ae0b204
JA
19}
20
3114b675 21void io_u_qexit(struct io_u_queue *q, bool shared)
2ae0b204 22{
3114b675
VF
23 if (shared)
24 sfree(q->io_us);
25 else
26 free(q->io_us);
2ae0b204
JA
27}
28
34851ad5 29bool io_u_rinit(struct io_u_ring *ring, unsigned int nr)
2ae0b204
JA
30{
31 ring->max = nr + 1;
32 if (ring->max & (ring->max - 1)) {
33 ring->max--;
34 ring->max |= ring->max >> 1;
35 ring->max |= ring->max >> 2;
36 ring->max |= ring->max >> 4;
37 ring->max |= ring->max >> 8;
38 ring->max |= ring->max >> 16;
39 ring->max++;
40 }
41
572cfb3f 42 ring->ring = calloc(ring->max, sizeof(struct io_u *));
2ae0b204 43 if (!ring->ring)
34851ad5 44 return false;
2ae0b204
JA
45
46 ring->head = ring->tail = 0;
34851ad5 47 return true;
2ae0b204
JA
48}
49
50void io_u_rexit(struct io_u_ring *ring)
51{
52 free(ring->ring);
53}