* @brief This function will delete a semaphore object and release the memory space. * * @note This function is used to delete a semaphore object which is created by the rt_sem_create() function. * By contrast, the rt_sem_detach() function will detach a static semaphore object. * When the semaphore is successfully deleted, it will resume all suspended threads in the s
| 504 | * ONLY USE the rt_sem_detach() function to complete the detachment. |
| 505 | */ |
| 506 | rt_err_t rt_sem_delete(rt_sem_t sem) |
| 507 | { |
| 508 | rt_ubase_t level; |
| 509 | |
| 510 | /* parameter check */ |
| 511 | RT_ASSERT(sem != RT_NULL); |
| 512 | RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore); |
| 513 | RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent) == RT_FALSE); |
| 514 | |
| 515 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 516 | |
| 517 | level = rt_spin_lock_irqsave(&(sem->spinlock)); |
| 518 | /* wakeup all suspended threads */ |
| 519 | rt_susp_list_resume_all(&(sem->parent.suspend_thread), RT_ERROR); |
| 520 | rt_spin_unlock_irqrestore(&(sem->spinlock), level); |
| 521 | |
| 522 | /* delete semaphore object */ |
| 523 | rt_object_delete(&(sem->parent.parent)); |
| 524 | |
| 525 | return RT_EOK; |
| 526 | } |
| 527 | RTM_EXPORT(rt_sem_delete); |
| 528 | #endif /* RT_USING_HEAP */ |
| 529 |