Skip to content

Commit f0944a3

Browse files
committed
Use CV to block the TX thread
1 parent cd0a069 commit f0944a3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

virtio-snd.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -870,18 +870,20 @@ static void virtio_queue_notify_handler(
870870
static void *func(void *args)
871871
{
872872
virtio_snd_state_t *vsnd = (virtio_snd_state_t *) args;
873-
fprintf(stderr, "*** tx desc handler is called ***\n");
874-
pthread_mutex_lock(&virtio_snd_mutex);
875-
while (tx_ev_notify <= 0) {
876-
pthread_cond_wait(&virtio_snd_tx_cond, &virtio_snd_mutex);
877-
fprintf(stderr, "wait for cond\n");
873+
for (;;) {
874+
fprintf(stderr, "*** tx desc handler is called ***\n");
875+
pthread_mutex_lock(&virtio_snd_mutex);
876+
while (tx_ev_notify <= 0) {
877+
pthread_cond_wait(&virtio_snd_tx_cond, &virtio_snd_mutex);
878+
fprintf(stderr, "wait for cond\n");
879+
}
880+
fprintf(stderr, "*** start tx critical section ***\n");
881+
tx_ev_notify--;
882+
fprintf(stderr, "*** tx desc handler ***\n");
883+
virtio_queue_notify_handler(vsnd, 2, virtio_snd_tx_desc_handler);
884+
fprintf(stderr, "*** end tx cirtical section ***\n");
885+
pthread_mutex_unlock(&virtio_snd_mutex);
878886
}
879-
fprintf(stderr, "*** start tx critical section ***\n");
880-
tx_ev_notify--;
881-
fprintf(stderr, "*** tx desc handler ***\n");
882-
virtio_queue_notify_handler(vsnd, 2, virtio_snd_tx_desc_handler);
883-
fprintf(stderr, "*** end tx cirtical section ***\n");
884-
pthread_mutex_unlock(&virtio_snd_mutex);
885887
return NULL;
886888
}
887889

0 commit comments

Comments
 (0)