FreeBSD/sys/dev/hyperv/vmbus/hv_ring_buffer.c
/**
 * @brief Read and advance the read index.
 */
@brief Read and advance the read index.
@brief Read and advance the read index .
int
hv_ring_buffer_read(
	hv_vmbus_ring_buffer_info*	in_ring_info,
	void*				buffer,
	uint32_t			buffer_len,
	uint32_t			offset)
{
	uint32_t bytes_avail_to_write;
	uint32_t bytes_avail_to_read;
	uint32_t next_read_location = 0;
	uint64_t prev_indices = 0;
	if (buffer_len <= 0)
	    return (EINVAL);
	mtx_lock_spin(&in_ring_info->ring_lock);
	get_ring_buffer_avail_bytes(
	    in_ring_info, &bytes_avail_to_read,
	    &bytes_avail_to_write);
	if (bytes_avail_to_read < buffer_len) {
	    mtx_unlock_spin(&in_ring_info->ring_lock);
	    return (EAGAIN);
	}
	next_read_location = get_next_read_location_with_offset(
	    in_ring_info,
	    offset);
	next_read_location = copy_from_ring_buffer(
	    in_ring_info,
	    (char *) buffer,
	    buffer_len,
	    next_read_location);
	next_read_location = copy_from_ring_buffer(
	    in_ring_info,
	    (char *) &prev_indices,
	    sizeof(uint64_t),
	    next_read_location);
	wmb();
	set_next_read_location(in_ring_info, next_read_location);
	mtx_unlock_spin(&in_ring_info->ring_lock);
	return (0);
}
int hv_ring_buffer_read ( hv_vmbus_ring_buffer_info * in_ring_info , void * buffer , uint32_t buffer_len , uint32_t offset ) { uint32_t bytes_avail_to_write ; uint32_t bytes_avail_to_read ; uint32_t next_read_location = 0 ; uint64_t prev_indices = 0 ; if ( buffer_len <= 0 ) return ( EINVAL ) ; mtx_lock_spin ( & in_ring_info -> ring_lock ) ; get_ring_buffer_avail_bytes ( in_ring_info , & bytes_avail_to_read , & bytes_avail_to_write ) ; if ( bytes_avail_to_read < buffer_len ) { mtx_unlock_spin ( & in_ring_info -> ring_lock ) ; return ( EAGAIN ) ; } next_read_location = get_next_read_location_with_offset ( in_ring_info , offset ) ; next_read_location = copy_from_ring_buffer ( in_ring_info , ( char * ) buffer , buffer_len , next_read_location ) ; next_read_location = copy_from_ring_buffer ( in_ring_info , ( char * ) & prev_indices , sizeof ( uint64_t ) , next_read_location ) ; wmb ( ) ; set_next_read_location ( in_ring_info , next_read_location ) ; mtx_unlock_spin ( & in_ring_info -> ring_lock ) ; return ( 0 ) ; }
@brief Read and advance the read index.
@brief Read and advance the read index .
/*
	 * Make sure there is something to read
	 */ /*
	 * Make sure all reads are done before we update the read index since
	 * the writer may start writing to the read area once the read index
	 * is updated.
	 */ /*
	 * Update the read index
	 */