Skip to content

Commit 3cc58ff

Browse files
committed
Fill buffer_bytes then go
1 parent ba1a738 commit 3cc58ff

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

virtio-snd.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,18 +616,22 @@ static void __virtio_snd_frame_dequeue(short *out,
616616
uint32_t stream_id)
617617
{
618618
virtio_snd_prop_t *props = &vsnd_props[stream_id];
619+
620+
pthread_mutex_lock(&props->ring.lock);
621+
619622
uint32_t cons_head, prod_tail;
620623
uint32_t cons_next, entries;
621624
uint32_t mask = props->ring.cons.mask;
622625

623-
pthread_mutex_lock(&props->ring.lock);
624-
while (props->ring.buf_ev_notity < 1) {
626+
uint32_t buffer_bytes = props->pp.buffer_bytes;
627+
cons_head = props->ring.cons.head;
628+
prod_tail = props->ring.prod.tail;
629+
while (props->ring.buf_ev_notity < 1 &&
630+
prod_tail - cons_head < buffer_bytes) {
625631
fprintf(stderr, "---wait in deque---\n");
626632
pthread_cond_wait(&props->ring.readable, &props->ring.lock);
627633
}
628634

629-
cons_head = props->ring.cons.head;
630-
prod_tail = props->ring.prod.tail;
631635
/* The subtraction is done between two unsigned 32bits value
632636
* (the result is always modulo 32 bits even if we have
633637
* cons_head > prod_tail). So 'entries' is always between 0
@@ -808,12 +812,14 @@ static void __virtio_snd_frame_enqueue(void *payload,
808812
uint32_t n,
809813
uint32_t stream_id)
810814
{
815+
virtio_snd_prop_t *props = &vsnd_props[stream_id];
816+
817+
pthread_mutex_lock(&props->ring.lock);
818+
811819
uint32_t prod_head, cons_tail;
812820
uint32_t prod_next, free_entries;
813-
virtio_snd_prop_t *props = &vsnd_props[stream_id];
814821
uint32_t mask = props->ring.prod.mask;
815822

816-
pthread_mutex_lock(&props->ring.lock);
817823
while (props->ring.buf_ev_notity > 0) {
818824
fprintf(stderr, "---wait for enque---\n");
819825
pthread_cond_wait(&props->ring.writable, &props->ring.lock);

0 commit comments

Comments
 (0)