/* This function will get the number of data in the data queue.  */
rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
/* This function will get the number of data in the data queue.  */
rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
{
    rt_base_t level;
    rt_int16_t len;
    RT_ASSERT(queue != RT_NULL);
    RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
    if (queue->is_empty)
    {
        return 0;
    }
    level = rt_spin_lock_irqsave(&(queue->spinlock));
    if (queue->put_index > queue->get_index)
    {
        len = queue->put_index - queue->get_index;
    }
    else
    {
        len = queue->size + queue->put_index - queue->get_index;
    }
    rt_spin_unlock_irqrestore(&(queue->spinlock), level);
    return len;
}