block: Emulate bdrv_ioctl with bdrv_aio_ioctl and track both
[qemu.git] / include / qemu / fifo8.h
blob882078066912396ea8f8c1e674c2236118e677d6
1 #ifndef FIFO_H
2 #define FIFO_H
4 #include "migration/vmstate.h"
6 typedef struct {
7 /* All fields are private */
8 uint8_t *data;
9 uint32_t capacity;
10 uint32_t head;
11 uint32_t num;
12 } Fifo8;
14 /**
15 * fifo8_create:
16 * @fifo: struct Fifo8 to initialise with new FIFO
17 * @capacity: capacity of the newly created FIFO
19 * Create a FIFO of the specified size. Clients should call fifo8_destroy()
20 * when finished using the fifo. The FIFO is initially empty.
23 void fifo8_create(Fifo8 *fifo, uint32_t capacity);
25 /**
26 * fifo8_destroy:
27 * @fifo: FIFO to cleanup
29 * Cleanup a FIFO created with fifo8_create(). Frees memory created for FIFO
30 *storage. The FIFO is no longer usable after this has been called.
33 void fifo8_destroy(Fifo8 *fifo);
35 /**
36 * fifo8_push:
37 * @fifo: FIFO to push to
38 * @data: data byte to push
40 * Push a data byte to the FIFO. Behaviour is undefined if the FIFO is full.
41 * Clients are responsible for checking for fullness using fifo8_is_full().
44 void fifo8_push(Fifo8 *fifo, uint8_t data);
46 /**
47 * fifo8_push_all:
48 * @fifo: FIFO to push to
49 * @data: data to push
50 * @size: number of bytes to push
52 * Push a byte array to the FIFO. Behaviour is undefined if the FIFO is full.
53 * Clients are responsible for checking the space left in the FIFO using
54 * fifo8_num_free().
57 void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num);
59 /**
60 * fifo8_pop:
61 * @fifo: fifo to pop from
63 * Pop a data byte from the FIFO. Behaviour is undefined if the FIFO is empty.
64 * Clients are responsible for checking for emptyness using fifo8_is_empty().
66 * Returns: The popped data byte.
69 uint8_t fifo8_pop(Fifo8 *fifo);
71 /**
72 * fifo8_pop_buf:
73 * @fifo: FIFO to pop from
74 * @max: maximum number of bytes to pop
75 * @num: actual number of returned bytes
77 * Pop a number of elements from the FIFO up to a maximum of max. The buffer
78 * containing the popped data is returned. This buffer points directly into
79 * the FIFO backing store and data is invalidated once any of the fifo8_* APIs
80 * are called on the FIFO.
82 * The function may return fewer bytes than requested when the data wraps
83 * around in the ring buffer; in this case only a contiguous part of the data
84 * is returned.
86 * The number of valid bytes returned is populated in *num; will always return
87 * at least 1 byte. max must not be 0 or greater than the number of bytes in
88 * the FIFO.
90 * Clients are responsible for checking the availability of requested data
91 * using fifo8_num_used().
93 * Returns: A pointer to popped data.
95 const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num);
97 /**
98 * fifo8_reset:
99 * @fifo: FIFO to reset
101 * Reset a FIFO. All data is discarded and the FIFO is emptied.
104 void fifo8_reset(Fifo8 *fifo);
107 * fifo8_is_empty:
108 * @fifo: FIFO to check
110 * Check if a FIFO is empty.
112 * Returns: True if the fifo is empty, false otherwise.
115 bool fifo8_is_empty(Fifo8 *fifo);
118 * fifo8_is_full:
119 * @fifo: FIFO to check
121 * Check if a FIFO is full.
123 * Returns: True if the fifo is full, false otherwise.
126 bool fifo8_is_full(Fifo8 *fifo);
129 * fifo8_num_free:
130 * @fifo: FIFO to check
132 * Return the number of free bytes in the FIFO.
134 * Returns: Number of free bytes.
137 uint32_t fifo8_num_free(Fifo8 *fifo);
140 * fifo8_num_used:
141 * @fifo: FIFO to check
143 * Return the number of used bytes in the FIFO.
145 * Returns: Number of used bytes.
148 uint32_t fifo8_num_used(Fifo8 *fifo);
150 extern const VMStateDescription vmstate_fifo8;
152 #define VMSTATE_FIFO8(_field, _state) { \
153 .name = (stringify(_field)), \
154 .size = sizeof(Fifo8), \
155 .vmsd = &vmstate_fifo8, \
156 .flags = VMS_STRUCT, \
157 .offset = vmstate_offset_value(_state, _field, Fifo8), \
160 #endif /* FIFO_H */