Home | History | Annotate | Download | only in fio
      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 	q->max = nr;
     12 	return 0;
     13 }
     14 
     15 void io_u_qexit(struct io_u_queue *q)
     16 {
     17 	free(q->io_us);
     18 }
     19 
     20 int io_u_rinit(struct io_u_ring *ring, unsigned int nr)
     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 
     33 	ring->ring = calloc(ring->max, sizeof(struct io_u *));
     34 	if (!ring->ring)
     35 		return 1;
     36 
     37 	ring->head = ring->tail = 0;
     38 	return 0;
     39 }
     40 
     41 void io_u_rexit(struct io_u_ring *ring)
     42 {
     43 	free(ring->ring);
     44 }
     45