blob: 80a32ba3afd20d4a8b3669935ca10d035720a554 [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{
Jens Axboe572cfb32013-12-06 12:02:10 -07006 q->io_us = calloc(nr, sizeof(struct io_u *));
Jens Axboe2ae0b202013-05-28 14:16:55 +02007 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
Jens Axboe572cfb32013-12-06 12:02:10 -070032 ring->ring = calloc(ring->max, sizeof(struct io_u *));
Jens Axboe2ae0b202013-05-28 14:16:55 +020033 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}