File: io_u_queue.c

package info (click to toggle)
fio 2.1.11-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,712 kB
  • ctags: 5,643
  • sloc: ansic: 44,396; sh: 1,489; python: 400; makefile: 342
file content (43 lines) | stat: -rw-r--r-- 762 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdlib.h>
#include "io_u_queue.h"

int io_u_qinit(struct io_u_queue *q, unsigned int nr)
{
	q->io_us = calloc(nr, sizeof(struct io_u *));
	if (!q->io_us)
		return 1;

	q->nr = 0;
	return 0;
}

void io_u_qexit(struct io_u_queue *q)
{
	free(q->io_us);
}

int io_u_rinit(struct io_u_ring *ring, unsigned int nr)
{
	ring->max = nr + 1;
	if (ring->max & (ring->max - 1)) {
		ring->max--;
		ring->max |= ring->max >> 1;
		ring->max |= ring->max >> 2;
		ring->max |= ring->max >> 4;
		ring->max |= ring->max >> 8;
		ring->max |= ring->max >> 16;
		ring->max++;
	}

	ring->ring = calloc(ring->max, sizeof(struct io_u *));
	if (!ring->ring)
		return 1;

	ring->head = ring->tail = 0;
	return 0;
}

void io_u_rexit(struct io_u_ring *ring)
{
	free(ring->ring);
}