gallium: Remove unused util_ringbuffer

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
This commit is contained in:
Caio Marcelo de Oliveira Filho
2019-06-12 16:14:52 -07:00
parent 397d1a18ef
commit 4b0bc664a5
4 changed files with 0 additions and 193 deletions
-2
View File
@@ -301,8 +301,6 @@ C_SOURCES := \
util/u_rect.h \
util/u_resource.c \
util/u_resource.h \
util/u_ringbuffer.c \
util/u_ringbuffer.h \
util/u_sampler.c \
util/u_sampler.h \
util/u_screen.c \
-2
View File
@@ -321,8 +321,6 @@ files_libgallium = files(
'util/u_rect.h',
'util/u_resource.c',
'util/u_resource.h',
'util/u_ringbuffer.c',
'util/u_ringbuffer.h',
'util/u_sampler.c',
'util/u_sampler.h',
'util/u_screen.c',
-160
View File
@@ -1,160 +0,0 @@
#include "os/os_thread.h"
#include "pipe/p_defines.h"
#include "util/u_ringbuffer.h"
#include "util/u_math.h"
#include "util/u_memory.h"
/* Generic ringbuffer:
*/
struct util_ringbuffer
{
struct util_packet *buf;
unsigned mask;
/* Can this be done with atomic variables??
*/
unsigned head;
unsigned tail;
cnd_t change;
mtx_t mutex;
};
struct util_ringbuffer *util_ringbuffer_create( unsigned dwords )
{
struct util_ringbuffer *ring = CALLOC_STRUCT(util_ringbuffer);
if (!ring)
return NULL;
assert(util_is_power_of_two_or_zero(dwords));
ring->buf = MALLOC( dwords * sizeof(unsigned) );
if (ring->buf == NULL)
goto fail;
ring->mask = dwords - 1;
cnd_init(&ring->change);
(void) mtx_init(&ring->mutex, mtx_plain);
return ring;
fail:
FREE(ring->buf);
FREE(ring);
return NULL;
}
void util_ringbuffer_destroy( struct util_ringbuffer *ring )
{
cnd_destroy(&ring->change);
mtx_destroy(&ring->mutex);
FREE(ring->buf);
FREE(ring);
}
/**
* Return number of free entries in the ring
*/
static inline unsigned util_ringbuffer_space( const struct util_ringbuffer *ring )
{
return (ring->tail - (ring->head + 1)) & ring->mask;
}
/**
* Is the ring buffer empty?
*/
static inline boolean util_ringbuffer_empty( const struct util_ringbuffer *ring )
{
return util_ringbuffer_space(ring) == ring->mask;
}
void util_ringbuffer_enqueue( struct util_ringbuffer *ring,
const struct util_packet *packet )
{
unsigned i;
/* XXX: over-reliance on mutexes, etc:
*/
mtx_lock(&ring->mutex);
/* make sure we don't request an impossible amount of space
*/
assert(packet->dwords <= ring->mask);
/* Wait for free space:
*/
while (util_ringbuffer_space(ring) < packet->dwords)
cnd_wait(&ring->change, &ring->mutex);
/* Copy data to ring:
*/
for (i = 0; i < packet->dwords; i++) {
/* Copy all dwords of the packet. Note we're abusing the
* typesystem a little - we're being passed a pointer to
* something, but probably not an array of packet structs:
*/
ring->buf[ring->head] = packet[i];
ring->head++;
ring->head &= ring->mask;
}
/* Signal change:
*/
cnd_signal(&ring->change);
mtx_unlock(&ring->mutex);
}
enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring,
struct util_packet *packet,
unsigned max_dwords,
boolean wait )
{
const struct util_packet *ring_packet;
unsigned i;
int ret = PIPE_OK;
/* XXX: over-reliance on mutexes, etc:
*/
mtx_lock(&ring->mutex);
/* Get next ring entry:
*/
if (wait) {
while (util_ringbuffer_empty(ring))
cnd_wait(&ring->change, &ring->mutex);
}
else {
if (util_ringbuffer_empty(ring)) {
ret = PIPE_ERROR_OUT_OF_MEMORY;
goto out;
}
}
ring_packet = &ring->buf[ring->tail];
/* Both of these are considered bugs. Raise an assert on debug builds.
*/
if (ring_packet->dwords > ring->mask + 1 - util_ringbuffer_space(ring) ||
ring_packet->dwords > max_dwords) {
assert(0);
ret = PIPE_ERROR_BAD_INPUT;
goto out;
}
/* Copy data from ring:
*/
for (i = 0; i < ring_packet->dwords; i++) {
packet[i] = ring->buf[ring->tail];
ring->tail++;
ring->tail &= ring->mask;
}
out:
/* Signal change:
*/
cnd_signal(&ring->change);
mtx_unlock(&ring->mutex);
return ret;
}
-29
View File
@@ -1,29 +0,0 @@
#ifndef UTIL_RINGBUFFER_H
#define UTIL_RINGBUFFER_H
#include "pipe/p_compiler.h"
#include "pipe/p_defines.h" /* only for pipe_error! */
/* Generic header
*/
struct util_packet {
unsigned dwords:8;
unsigned data24:24;
};
struct util_ringbuffer;
struct util_ringbuffer *util_ringbuffer_create( unsigned dwords );
void util_ringbuffer_destroy( struct util_ringbuffer *ring );
void util_ringbuffer_enqueue( struct util_ringbuffer *ring,
const struct util_packet *packet );
enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring,
struct util_packet *packet,
unsigned max_dwords,
boolean wait );
#endif