* @brief This function will delete a mailbox object and release the memory space. * * @note This function is used to delete a mailbox object which is created by the rt_mb_create() function. * By contrast, the rt_mb_detach() function will detach a static mailbox object. * When the mailbox is successfully deleted, it will resume all suspended threads in the mailbox lis
| 2511 | * ONLY USE the rt_mb_detach() function to complete the detachment. |
| 2512 | */ |
| 2513 | rt_err_t rt_mb_delete(rt_mailbox_t mb) |
| 2514 | { |
| 2515 | /* parameter check */ |
| 2516 | RT_ASSERT(mb != RT_NULL); |
| 2517 | RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox); |
| 2518 | RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent) == RT_FALSE); |
| 2519 | |
| 2520 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 2521 | rt_spin_lock(&(mb->spinlock)); |
| 2522 | |
| 2523 | /* resume all suspended thread */ |
| 2524 | rt_susp_list_resume_all(&(mb->parent.suspend_thread), RT_ERROR); |
| 2525 | |
| 2526 | /* also resume all mailbox private suspended thread */ |
| 2527 | rt_susp_list_resume_all(&(mb->suspend_sender_thread), RT_ERROR); |
| 2528 | |
| 2529 | rt_spin_unlock(&(mb->spinlock)); |
| 2530 | |
| 2531 | /* free mailbox pool */ |
| 2532 | RT_KERNEL_FREE(mb->msg_pool); |
| 2533 | |
| 2534 | /* delete mailbox object */ |
| 2535 | rt_object_delete(&(mb->parent.parent)); |
| 2536 | |
| 2537 | return RT_EOK; |
| 2538 | } |
| 2539 | RTM_EXPORT(rt_mb_delete); |
| 2540 | #endif /* RT_USING_HEAP */ |
| 2541 |