[components][dataqueue]add rt_data_queue_deinit
This commit is contained in:
parent
0f57faa591
commit
dfcd38b74d
|
@ -25,6 +25,7 @@ struct rt_data_queue
|
||||||
rt_uint16_t size;
|
rt_uint16_t size;
|
||||||
rt_uint16_t lwm;
|
rt_uint16_t lwm;
|
||||||
rt_bool_t waiting_lwm;
|
rt_bool_t waiting_lwm;
|
||||||
|
rt_bool_t is_init;
|
||||||
|
|
||||||
rt_uint16_t get_index;
|
rt_uint16_t get_index;
|
||||||
rt_uint16_t put_index;
|
rt_uint16_t put_index;
|
||||||
|
@ -57,5 +58,6 @@ rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
|
||||||
const void **data_ptr,
|
const void **data_ptr,
|
||||||
rt_size_t *size);
|
rt_size_t *size);
|
||||||
void rt_data_queue_reset(struct rt_data_queue *queue);
|
void rt_data_queue_reset(struct rt_data_queue *queue);
|
||||||
|
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,6 +31,7 @@ rt_data_queue_init(struct rt_data_queue *queue,
|
||||||
|
|
||||||
queue->size = size;
|
queue->size = size;
|
||||||
queue->lwm = lwm;
|
queue->lwm = lwm;
|
||||||
|
queue->is_init = RT_TRUE;
|
||||||
|
|
||||||
queue->get_index = 0;
|
queue->get_index = 0;
|
||||||
queue->put_index = 0;
|
queue->put_index = 0;
|
||||||
|
@ -57,6 +58,11 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||||
rt_thread_t thread;
|
rt_thread_t thread;
|
||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
|
|
||||||
|
if(queue->is_init != RT_TRUE)
|
||||||
|
{
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
|
|
||||||
result = RT_EOK;
|
result = RT_EOK;
|
||||||
|
@ -146,6 +152,11 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||||
rt_thread_t thread;
|
rt_thread_t thread;
|
||||||
rt_err_t result;
|
rt_err_t result;
|
||||||
|
|
||||||
|
if(queue->is_init != RT_TRUE)
|
||||||
|
{
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
RT_ASSERT(data_ptr != RT_NULL);
|
RT_ASSERT(data_ptr != RT_NULL);
|
||||||
RT_ASSERT(size != RT_NULL);
|
RT_ASSERT(size != RT_NULL);
|
||||||
|
@ -245,6 +256,11 @@ rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
|
||||||
{
|
{
|
||||||
rt_ubase_t level;
|
rt_ubase_t level;
|
||||||
|
|
||||||
|
if(queue->is_init != RT_TRUE)
|
||||||
|
{
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
RT_ASSERT(queue != RT_NULL);
|
RT_ASSERT(queue != RT_NULL);
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
@ -270,6 +286,11 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||||
struct rt_thread *thread;
|
struct rt_thread *thread;
|
||||||
register rt_ubase_t temp;
|
register rt_ubase_t temp;
|
||||||
|
|
||||||
|
if(queue->is_init != RT_TRUE)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rt_enter_critical();
|
rt_enter_critical();
|
||||||
/* wakeup all suspend threads */
|
/* wakeup all suspend threads */
|
||||||
|
|
||||||
|
@ -325,3 +346,28 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||||
rt_schedule();
|
rt_schedule();
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_data_queue_reset);
|
RTM_EXPORT(rt_data_queue_reset);
|
||||||
|
|
||||||
|
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
|
||||||
|
{
|
||||||
|
rt_ubase_t level;
|
||||||
|
|
||||||
|
if(queue->is_init != RT_TRUE)
|
||||||
|
{
|
||||||
|
return RT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
RT_ASSERT(queue != RT_NULL);
|
||||||
|
|
||||||
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
|
/* wakeup all suspend threads */
|
||||||
|
rt_data_queue_reset(queue);
|
||||||
|
|
||||||
|
queue->is_init = RT_FALSE;
|
||||||
|
rt_free(queue->queue);
|
||||||
|
|
||||||
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
RTM_EXPORT(rt_data_queue_deinit);
|
||||||
|
|
Loading…
Reference in New Issue