summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util/u_ringbuffer.c
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2010-02-05 13:48:35 +0000
committerJosé Fonseca <[email protected]>2010-02-05 13:48:35 +0000
commita1af8eec66c5f7ec421e8011b41c1a7c36319f9f (patch)
treebc76a431699807cf60cf8ba82ff6b3b1ff34f309 /src/gallium/auxiliary/util/u_ringbuffer.c
parentc036d13d7d2cc905226fe53ebd86a18da808963f (diff)
parentbee9964b29b2428ee75e2d1efc0e1d2c2518a417 (diff)
Merge remote branch 'origin/lp-binning'
Conflicts: src/gallium/auxiliary/util/u_dl.c src/gallium/auxiliary/util/u_time.h src/gallium/drivers/llvmpipe/lp_state_derived.c src/gallium/drivers/llvmpipe/lp_state_surface.c src/gallium/drivers/llvmpipe/lp_tex_cache.c src/gallium/drivers/llvmpipe/lp_tile_cache.c
Diffstat (limited to 'src/gallium/auxiliary/util/u_ringbuffer.c')
-rw-r--r--src/gallium/auxiliary/util/u_ringbuffer.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/gallium/auxiliary/util/u_ringbuffer.c b/src/gallium/auxiliary/util/u_ringbuffer.c
index 95d45ebb71f..648b105b137 100644
--- a/src/gallium/auxiliary/util/u_ringbuffer.c
+++ b/src/gallium/auxiliary/util/u_ringbuffer.c
@@ -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;
}