Merge pull request #3503 from yangjie11/yj_dev

[components][dataqueue]add rt_data_queue_deinit
This commit is contained in:
Bernard Xiong 2020-04-10 15:41:32 +08:00 committed by GitHub
commit 6375094569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -22,6 +22,8 @@ struct rt_data_item;
/* data queue implementation */
struct rt_data_queue
{
rt_uint32_t magic;
rt_uint16_t size;
rt_uint16_t lwm;
rt_bool_t waiting_lwm;
@ -57,5 +59,6 @@ rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
const void **data_ptr,
rt_size_t *size);
void rt_data_queue_reset(struct rt_data_queue *queue);
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue);
#endif

View File

@ -13,6 +13,8 @@
#include <rtdevice.h>
#include <rthw.h>
#define DATAQUEUE_MAGIC 0xbead0e0e
struct rt_data_item
{
const void *data_ptr;
@ -29,6 +31,7 @@ rt_data_queue_init(struct rt_data_queue *queue,
queue->evt_notify = evt_notify;
queue->magic = DATAQUEUE_MAGIC;
queue->size = size;
queue->lwm = lwm;
@ -57,6 +60,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
rt_thread_t thread;
rt_err_t result;
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
RT_ASSERT(queue != RT_NULL);
result = RT_EOK;
@ -145,7 +149,8 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
rt_ubase_t level;
rt_thread_t thread;
rt_err_t result;
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
RT_ASSERT(queue != RT_NULL);
RT_ASSERT(data_ptr != RT_NULL);
RT_ASSERT(size != RT_NULL);
@ -244,7 +249,8 @@ rt_err_t rt_data_queue_peak(struct rt_data_queue *queue,
rt_size_t *size)
{
rt_ubase_t level;
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
RT_ASSERT(queue != RT_NULL);
level = rt_hw_interrupt_disable();
@ -269,7 +275,9 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
{
struct rt_thread *thread;
register rt_ubase_t temp;
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
rt_enter_critical();
/* wakeup all suspend threads */
@ -325,3 +333,24 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
rt_schedule();
}
RTM_EXPORT(rt_data_queue_reset);
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
{
rt_ubase_t level;
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
RT_ASSERT(queue != RT_NULL);
level = rt_hw_interrupt_disable();
/* wakeup all suspend threads */
rt_data_queue_reset(queue);
queue->magic = 0;
rt_free(queue->queue);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
RTM_EXPORT(rt_data_queue_deinit);