* @brief This function will delete a messagequeue object and release the memory. * * @note This function is used to delete a messagequeue object which is created by the rt_mq_create() function. * By contrast, the rt_mq_detach() function will detach a static messagequeue object. * When the messagequeue is successfully deleted, it will resume all suspended threads in t
| 3318 | * for example,the rt_mq_create() function, it cannot be called in interrupt context. |
| 3319 | */ |
| 3320 | rt_err_t rt_mq_delete(rt_mq_t mq) |
| 3321 | { |
| 3322 | /* parameter check */ |
| 3323 | RT_ASSERT(mq != RT_NULL); |
| 3324 | RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue); |
| 3325 | RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent) == RT_FALSE); |
| 3326 | |
| 3327 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 3328 | |
| 3329 | rt_spin_lock(&(mq->spinlock)); |
| 3330 | /* resume all suspended thread */ |
| 3331 | rt_susp_list_resume_all(&(mq->parent.suspend_thread), RT_ERROR); |
| 3332 | /* also resume all message queue private suspended thread */ |
| 3333 | rt_susp_list_resume_all(&(mq->suspend_sender_thread), RT_ERROR); |
| 3334 | |
| 3335 | rt_spin_unlock(&(mq->spinlock)); |
| 3336 | |
| 3337 | /* free message queue pool */ |
| 3338 | RT_KERNEL_FREE(mq->msg_pool); |
| 3339 | |
| 3340 | /* delete message queue object */ |
| 3341 | rt_object_delete(&(mq->parent.parent)); |
| 3342 | |
| 3343 | return RT_EOK; |
| 3344 | } |
| 3345 | RTM_EXPORT(rt_mq_delete); |
| 3346 | #endif /* RT_USING_HEAP */ |
| 3347 |