Monado OpenXR Runtime
u_index_fifo.h
Go to the documentation of this file.
1// Copyright 2020-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief A FIFO for indices.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_util
8 */
9
10#pragma once
11
12#include "xrt/xrt_compiler.h"
13
14#include <stdint.h>
15#include <stddef.h>
16
17
18#define U_MAX_FIFO_INDICES 16
19
21{
22 uint32_t indices[U_MAX_FIFO_INDICES];
23 size_t start;
24 size_t end;
25};
26
27static inline int
28u_index_fifo_is_empty(struct u_index_fifo *uif)
29{
30 if (uif->start == uif->end) {
31 return 1;
32 }
33 return 0;
34}
35
36static inline int
37u_index_fifo_is_full(struct u_index_fifo *uif)
38{
39 if (((uif->end + 1) % U_MAX_FIFO_INDICES) == uif->start) {
40 return 1;
41 }
42 return 0;
43}
44
45static inline int
46u_index_fifo_peek(struct u_index_fifo *uif, uint32_t *out_index)
47{
48 if (u_index_fifo_is_empty(uif)) {
49 return -1;
50 }
51
52 *out_index = uif->indices[uif->start];
53 return 0;
54}
55
56static inline int
57u_index_fifo_pop(struct u_index_fifo *uif, uint32_t *out_index)
58{
59 if (u_index_fifo_is_empty(uif)) {
60 return -1;
61 }
62
63 *out_index = uif->indices[uif->start];
64 uif->start = (uif->start + 1) % U_MAX_FIFO_INDICES;
65 return 0;
66}
67
68static inline int
69u_index_fifo_push(struct u_index_fifo *uif, uint32_t index)
70{
71 if (u_index_fifo_is_full(uif)) {
72 return -1;
73 }
74
75 uif->indices[uif->end] = index;
76 uif->end = (uif->end + 1) % U_MAX_FIFO_INDICES;
77
78 return 0;
79}
Definition: u_index_fifo.h:21
Header holding common defines.