Skip to content

Commit

Permalink
Fill buffer_bytes then go
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuda-Chen committed Dec 30, 2024
1 parent ba1a738 commit 3cc58ff
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions virtio-snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,18 +616,22 @@ static void __virtio_snd_frame_dequeue(short *out,
uint32_t stream_id)
{
virtio_snd_prop_t *props = &vsnd_props[stream_id];

pthread_mutex_lock(&props->ring.lock);

uint32_t cons_head, prod_tail;
uint32_t cons_next, entries;
uint32_t mask = props->ring.cons.mask;

pthread_mutex_lock(&props->ring.lock);
while (props->ring.buf_ev_notity < 1) {
uint32_t buffer_bytes = props->pp.buffer_bytes;
cons_head = props->ring.cons.head;
prod_tail = props->ring.prod.tail;
while (props->ring.buf_ev_notity < 1 &&
prod_tail - cons_head < buffer_bytes) {
fprintf(stderr, "---wait in deque---\n");
pthread_cond_wait(&props->ring.readable, &props->ring.lock);
}

cons_head = props->ring.cons.head;
prod_tail = props->ring.prod.tail;
/* The subtraction is done between two unsigned 32bits value
* (the result is always modulo 32 bits even if we have
* cons_head > prod_tail). So 'entries' is always between 0
Expand Down Expand Up @@ -808,12 +812,14 @@ static void __virtio_snd_frame_enqueue(void *payload,
uint32_t n,
uint32_t stream_id)
{
virtio_snd_prop_t *props = &vsnd_props[stream_id];

pthread_mutex_lock(&props->ring.lock);

uint32_t prod_head, cons_tail;
uint32_t prod_next, free_entries;
virtio_snd_prop_t *props = &vsnd_props[stream_id];
uint32_t mask = props->ring.prod.mask;

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

0 comments on commit 3cc58ff

Please sign in to comment.