util: Add a index fifo

This commit is contained in:
Jakob Bornecrantz 2020-05-30 16:22:58 +01:00
parent 371622c199
commit 0d2a24b9a0
2 changed files with 78 additions and 0 deletions

View 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).

View 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;
}