MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_data_queue_init

Function rt_data_queue_init

components/drivers/ipc/dataqueue.c:42–74  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

40 * When the return value is -RT_ENOMEM, it means insufficient memory allocation failed.
41 */
42rt_err_t
43rt_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}
75RTM_EXPORT(rt_data_queue_init);
76
77/**

Callers 2

ifFunction · 0.85
_audio_dev_initFunction · 0.85

Calls 3

rt_list_initFunction · 0.85
rt_mallocFunction · 0.85
rt_spin_lock_initFunction · 0.50

Tested by

no test coverage detected