Skip to content

Commit

Permalink
Remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuda-Chen committed Jan 13, 2025
1 parent 298f7da commit bd3e192
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions virtio-snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,8 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
cnt++;

/* Leave the loop if next-flag is not set */
if (!(desc[3] & VIRTIO_DESC_F_NEXT)) {
// fprintf(stderr, "index %" PRIu32 " no next flag\n", cnt);
if (!(desc[3] & VIRTIO_DESC_F_NEXT))
break;
}
}

int idx = 0;
Expand All @@ -953,30 +951,23 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
list_for_each_entry (node, &q, q) {
uint32_t addr = node->vq_desc.addr;
uint32_t len = node->vq_desc.len;
// fprintf(stderr, "idx %d addr %" PRIu32 " len %" PRIu32 "\n", idx,
// addr, len);
if (idx == 0) { // the first descriptor
if (idx == 0) { /* the first descriptor */
const virtio_snd_pcm_xfer_t *request =
(virtio_snd_pcm_xfer_t *) (base + addr);
stream_id = request->stream_id;
// fprintf(stderr, "stream_id %" PRIu32 "\n", stream_id);
goto early_continue;
} else if (idx == cnt - 1) { // the last descriptor
} else if (idx == cnt - 1) { /* the last descriptor */
virtio_snd_pcm_status_t *response =
(virtio_snd_pcm_status_t *) (base + addr);
response->status = VIRTIO_SND_S_OK;
response->latency_bytes = ret_len;
*plen = sizeof(*response);
// fprintf(stderr, "TX response\n");
goto early_continue;
}

/* TODO: ring buffer copy here */
void *payload = (void *) (base + addr);
__virtio_snd_frame_enqueue(payload, len, stream_id);
/* XXX: test only */
/*fprintf(stderr, "prod tail: %" PRIu32 "\n",
vsnd_props[stream_id].ring.prod.tail);*/
ret_len += len;

early_continue:
Expand Down Expand Up @@ -1040,7 +1031,6 @@ static void virtio_queue_notify_handler(
*/
uint32_t len = 0;
int result = handler(vsnd, queue, buffer_idx, &len);
// fprintf(stderr, "len: %" PRIu32 "\n", len);
if (result != 0)
return virtio_snd_set_fail(vsnd);

Expand All @@ -1052,40 +1042,29 @@ static void virtio_queue_notify_handler(
ram[vq_used_addr + 1] = len; /* virtq_used_elem.len (le32) */
queue->last_avail++;
new_used++;

// fprintf(stderr, "last_avail %d new_avail %d\n", queue->last_avail,
// new_avail);
}

/* Check le32 len field of struct virtq_used_elem on the spec */
vsnd->ram[queue->QueueUsed] &= MASK(16); /* Reset low 16 bits to zero */
vsnd->ram[queue->QueueUsed] |= ((uint32_t) new_used) << 16; /* len */

/* Send interrupt, unless VIRTQ_AVAIL_F_NO_INTERRUPT is set */
if (!(ram[queue->QueueAvail] & 1)) {
// fprintf(stderr, "send interrupt\n");
if (!(ram[queue->QueueAvail] & 1))
vsnd->InterruptStatus |= VIRTIO_INT__USED_RING;
}
}

/* TX thread context
* TODO: need to let this thread become a daemon.
*/
/* TX thread context */
static void *func(void *args)
{
virtio_snd_state_t *vsnd = (virtio_snd_state_t *) args;
for (;;) {
// fprintf(stderr, "*** tx desc handler is called ***\n");
pthread_mutex_lock(&virtio_snd_mutex);
while (tx_ev_notify <= 0) {
while (tx_ev_notify <= 0)
pthread_cond_wait(&virtio_snd_tx_cond, &virtio_snd_mutex);
// fprintf(stderr, "wait for cond\n");
}
// fprintf(stderr, "*** start tx critical section ***\n");

tx_ev_notify--;
// fprintf(stderr, "*** tx desc handler ***\n");
virtio_queue_notify_handler(vsnd, 2, virtio_snd_tx_desc_handler);
// fprintf(stderr, "*** end tx cirtical section ***\n");

pthread_mutex_unlock(&virtio_snd_mutex);
}
pthread_exit(NULL);
Expand Down

0 comments on commit bd3e192

Please sign in to comment.