* @brief This function will get the number of data in the data queue. * * @param queue is a pointer to the data queue object. * * @return Return the number of data in the data queue. */
| 430 | * @return Return the number of data in the data queue. |
| 431 | */ |
| 432 | rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue) |
| 433 | { |
| 434 | rt_base_t level; |
| 435 | rt_int16_t len; |
| 436 | |
| 437 | RT_ASSERT(queue != RT_NULL); |
| 438 | RT_ASSERT(queue->magic == DATAQUEUE_MAGIC); |
| 439 | |
| 440 | if (queue->is_empty) |
| 441 | { |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | level = rt_spin_lock_irqsave(&(queue->spinlock)); |
| 446 | |
| 447 | if (queue->put_index > queue->get_index) |
| 448 | { |
| 449 | len = queue->put_index - queue->get_index; |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | len = queue->size + queue->put_index - queue->get_index; |
| 454 | } |
| 455 | |
| 456 | rt_spin_unlock_irqrestore(&(queue->spinlock), level); |
| 457 | |
| 458 | return len; |
| 459 | } |
| 460 | RTM_EXPORT(rt_data_queue_len); |
| 461 |
no test coverage detected