mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
util: Add a index fifo
This commit is contained in:
parent
371622c199
commit
0d2a24b9a0
2
doc/changes/auxiliary/mr.359.1.md
Normal file
2
doc/changes/auxiliary/mr.359.1.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
util: Add a very simple fifo for indices, this is used to keep track of
|
||||
swapchain in order of age (oldness).
|
76
src/xrt/auxiliary/util/u_index_fifo.h
Normal file
76
src/xrt/auxiliary/util/u_index_fifo.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
// Copyright 2020, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief A FIFO for indices.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @ingroup aux_util
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#define U_MAX_FIFO_INDICES 16
|
||||
|
||||
struct u_index_fifo
|
||||
{
|
||||
uint32_t indices[U_MAX_FIFO_INDICES];
|
||||
size_t start;
|
||||
size_t end;
|
||||
};
|
||||
|
||||
static inline int
|
||||
u_index_fifo_is_empty(struct u_index_fifo *uif)
|
||||
{
|
||||
if (uif->start == uif->end) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
u_index_fifo_is_full(struct u_index_fifo *uif)
|
||||
{
|
||||
if (((uif->end + 1) % U_MAX_FIFO_INDICES) == uif->start) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
u_index_fifo_peek(struct u_index_fifo *uif, uint32_t *out_index)
|
||||
{
|
||||
if (u_index_fifo_is_empty(uif)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out_index = uif->indices[uif->start];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
u_index_fifo_pop(struct u_index_fifo *uif, uint32_t *out_index)
|
||||
{
|
||||
if (u_index_fifo_is_empty(uif)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out_index = uif->indices[uif->start];
|
||||
uif->start = (uif->start + 1) % U_MAX_FIFO_INDICES;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
u_index_fifo_push(struct u_index_fifo *uif, uint32_t index)
|
||||
{
|
||||
if (u_index_fifo_is_full(uif)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uif->indices[uif->end] = index;
|
||||
uif->end = (uif->end + 1) % U_MAX_FIFO_INDICES;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue