* @brief This function will initialize the data queue. Calling this function will * initialize the data queue control block and set the notification callback function. * * @param queue is a pointer to the data queue object. * * @param size is the maximum number of data in the data queue. * * @param lwm is low water mark. * When the number of data in the data
| 40 | * When the return value is -RT_ENOMEM, it means insufficient memory allocation failed. |
| 41 | */ |
| 42 | rt_err_t |
| 43 | rt_data_queue_init(struct rt_data_queue *queue, |
| 44 | rt_uint16_t size, |
| 45 | rt_uint16_t lwm, |
| 46 | void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event)) |
| 47 | { |
| 48 | RT_ASSERT(queue != RT_NULL); |
| 49 | RT_ASSERT(size > 0); |
| 50 | |
| 51 | queue->evt_notify = evt_notify; |
| 52 | |
| 53 | queue->magic = DATAQUEUE_MAGIC; |
| 54 | queue->size = size; |
| 55 | queue->lwm = lwm; |
| 56 | |
| 57 | queue->get_index = 0; |
| 58 | queue->put_index = 0; |
| 59 | queue->is_empty = 1; |
| 60 | queue->is_full = 0; |
| 61 | |
| 62 | rt_spin_lock_init(&(queue->spinlock)); |
| 63 | |
| 64 | rt_list_init(&(queue->suspended_push_list)); |
| 65 | rt_list_init(&(queue->suspended_pop_list)); |
| 66 | |
| 67 | queue->queue = (struct rt_data_item *)rt_malloc(sizeof(struct rt_data_item) * size); |
| 68 | if (queue->queue == RT_NULL) |
| 69 | { |
| 70 | return -RT_ENOMEM; |
| 71 | } |
| 72 | |
| 73 | return RT_EOK; |
| 74 | } |
| 75 | RTM_EXPORT(rt_data_queue_init); |
| 76 | |
| 77 | /** |
no test coverage detected