X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Futil%2Fu_ringbuffer.c;h=648b105b137524b3851b1dc3710e8333a79d2dc3;hb=10dd0cad67ebd0476c9e4de522af3eea136b0e93;hp=3f43a19e018988f4187154c5074ade6aa9f71984;hpb=9b22427911ad27efc1f36faee9462c6082d0417c;p=mesa.git diff --git a/src/gallium/auxiliary/util/u_ringbuffer.c b/src/gallium/auxiliary/util/u_ringbuffer.c index 3f43a19e018..648b105b137 100644 --- a/src/gallium/auxiliary/util/u_ringbuffer.c +++ b/src/gallium/auxiliary/util/u_ringbuffer.c @@ -1,5 +1,5 @@ -#include "pipe/p_thread.h" +#include "os/os_thread.h" #include "pipe/p_defines.h" #include "util/u_ringbuffer.h" #include "util/u_math.h" @@ -53,11 +53,22 @@ void util_ringbuffer_destroy( struct util_ringbuffer *ring ) 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 ) { @@ -67,6 +78,10 @@ void util_ringbuffer_enqueue( struct util_ringbuffer *ring, */ pipe_mutex_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) @@ -104,14 +119,14 @@ enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring, */ pipe_mutex_lock(ring->mutex); - /* Wait for free space: + /* Get next ring entry: */ if (wait) { - while (util_ringbuffer_space(ring) == 0) + while (util_ringbuffer_empty(ring)) pipe_condvar_wait(ring->change, ring->mutex); } else { - if (util_ringbuffer_space(ring) == 0) { + if (util_ringbuffer_empty(ring)) { ret = PIPE_ERROR_OUT_OF_MEMORY; goto out; }