Changeset 417aaafb in mainline for uspace/lib/virtio/virtio.c


Ignore:
Timestamp:
2018-06-25T21:37:48Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3107e2
Parents:
ea6840d
Message:

Protect the virtqueue with a mutex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/virtio/virtio.c

    rea6840d r417aaafb  
    6363        virtq_t *q = &vdev->queues[num];
    6464
     65        fibril_mutex_lock(&q->lock);
    6566        uint16_t idx = pio_read_le16(&q->avail->idx);
    6667        pio_write_le16(&q->avail->ring[idx % q->queue_size], descno);
     
    6970        write_barrier();
    7071        pio_write_le16(q->notify, num);
     72        fibril_mutex_unlock(&q->lock);
    7173}
    7274
     
    7678        virtq_t *q = &vdev->queues[num];
    7779
     80        fibril_mutex_lock(&q->lock);
    7881        uint16_t last_idx = q->used_last_idx % q->queue_size;
    79         if (last_idx == (pio_read_le16(&q->used->idx) % q->queue_size))
     82        if (last_idx == (pio_read_le16(&q->used->idx) % q->queue_size)) {
     83                fibril_mutex_unlock(&q->lock);
    8084                return false;
     85        }
    8186
    8287        *descno = (uint16_t) pio_read_le32(&q->used->ring[last_idx].id);
     
    8489
    8590        q->used_last_idx++;
     91        fibril_mutex_unlock(&q->lock);
    8692
    8793        return true;
     
    132138        }
    133139
     140        fibril_mutex_initialize(&q->lock);
     141
    134142        q->size = mem_size;
    135143        q->queue_size = size;
Note: See TracChangeset for help on using the changeset viewer.