blob: 5734e9c399cc9fc48238bf1c8c943f956b7dbf72 [file] [log] [blame]
Jens Axboe2ae0b202013-05-28 14:16:55 +02001#include <stdlib.h>
2#include "io_u_queue.h"
3
4int io_u_qinit(struct io_u_queue *q, unsigned int nr)
5{
6 q->io_us = calloc(sizeof(struct io_u *), nr);
7 if (!q->io_us)
8 return 1;
9
10 q->nr = 0;
11 return 0;
12}
13
14void io_u_qexit(struct io_u_queue *q)
15{
16 free(q->io_us);
17}
18
19int io_u_rinit(struct io_u_ring *ring, unsigned int nr)
20{
21 ring->max = nr + 1;
22 if (ring->max & (ring->max - 1)) {
23 ring->max--;
24 ring->max |= ring->max >> 1;
25 ring->max |= ring->max >> 2;
26 ring->max |= ring->max >> 4;
27 ring->max |= ring->max >> 8;
28 ring->max |= ring->max >> 16;
29 ring->max++;
30 }
31
32 ring->ring = calloc(sizeof(struct io_u *), ring->max);
33 if (!ring->ring)
34 return 1;
35
36 ring->head = ring->tail = 0;
37 return 0;
38}
39
40void io_u_rexit(struct io_u_ring *ring)
41{
42 free(ring->ring);
43}