Home | History | Annotate | Download | only in util

Lines Matching defs:ring

26    struct util_ringbuffer *ring = CALLOC_STRUCT(util_ringbuffer);
27 if (ring == NULL)
32 ring->buf = MALLOC( dwords * sizeof(unsigned) );
33 if (ring->buf == NULL)
36 ring->mask = dwords - 1;
38 pipe_condvar_init(ring->change);
39 pipe_mutex_init(ring->mutex);
40 return ring;
43 FREE(ring->buf);
44 FREE(ring);
48 void util_ringbuffer_destroy( struct util_ringbuffer *ring )
50 pipe_condvar_destroy(ring->change);
51 pipe_mutex_destroy(ring->mutex);
52 FREE(ring->buf);
53 FREE(ring);
57 * Return number of free entries in the ring
59 static INLINE unsigned util_ringbuffer_space( const struct util_ringbuffer *ring )
61 return (ring->tail - (ring->head + 1)) & ring->mask;
65 * Is the ring buffer empty?
67 static INLINE boolean util_ringbuffer_empty( const struct util_ringbuffer *ring )
69 return util_ringbuffer_space(ring) == ring->mask;
72 void util_ringbuffer_enqueue( struct util_ringbuffer *ring,
79 pipe_mutex_lock(ring->mutex);
83 assert(packet->dwords <= ring->mask);
87 while (util_ringbuffer_space(ring) < packet->dwords)
88 pipe_condvar_wait(ring->change, ring->mutex);
90 /* Copy data to ring:
98 ring->buf[ring->head] = packet[i];
99 ring->head++;
100 ring->head &= ring->mask;
105 pipe_condvar_signal(ring->change);
106 pipe_mutex_unlock(ring->mutex);
109 enum pipe_error util_ringbuffer_dequeue( struct util_ringbuffer *ring,
120 pipe_mutex_lock(ring->mutex);
122 /* Get next ring entry:
125 while (util_ringbuffer_empty(ring))
126 pipe_condvar_wait(ring->change, ring->mutex);
129 if (util_ringbuffer_empty(ring)) {
135 ring_packet = &ring->buf[ring->tail];
139 if (ring_packet->dwords > ring->mask + 1 - util_ringbuffer_space(ring) ||
146 /* Copy data from ring:
149 packet[i] = ring->buf[ring->tail];
150 ring->tail++;
151 ring->tail &= ring->mask;
157 pipe_condvar_signal(ring->change);
158 pipe_mutex_unlock(ring->mutex);