1 #include <stdlib.h> 2 #include "io_u_queue.h" 3 4 int io_u_qinit(struct io_u_queue *q, unsigned int nr) 5 { 6 q->io_us = calloc(nr, sizeof(struct io_u *)); 7 if (!q->io_us) 8 return 1; 9 10 q->nr = 0; 11 return 0; 12 } 13 14 void io_u_qexit(struct io_u_queue *q) 15 { 16 free(q->io_us); 17 } 18 19 int 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(ring->max, sizeof(struct io_u *)); 33 if (!ring->ring) 34 return 1; 35 36 ring->head = ring->tail = 0; 37 return 0; 38 } 39 40 void io_u_rexit(struct io_u_ring *ring) 41 { 42 free(ring->ring); 43 } 44