* @brief This function will detach a static semaphore object. * * @note This function is used to detach a static semaphore object which is initialized by rt_sem_init() function. * By contrast, the rt_sem_delete() function will delete a semaphore object. * When the semaphore is successfully detached, it will resume all suspended threads in the semaphore list. * * @s
| 411 | * ONLY USE the rt_sem_delete() function to complete the deletion. |
| 412 | */ |
| 413 | rt_err_t rt_sem_detach(rt_sem_t sem) |
| 414 | { |
| 415 | rt_base_t level; |
| 416 | |
| 417 | /* parameter check */ |
| 418 | RT_ASSERT(sem != RT_NULL); |
| 419 | RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore); |
| 420 | RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent)); |
| 421 | |
| 422 | level = rt_spin_lock_irqsave(&(sem->spinlock)); |
| 423 | /* wakeup all suspended threads */ |
| 424 | rt_susp_list_resume_all(&(sem->parent.suspend_thread), RT_ERROR); |
| 425 | rt_spin_unlock_irqrestore(&(sem->spinlock), level); |
| 426 | |
| 427 | /* detach semaphore object */ |
| 428 | rt_object_detach(&(sem->parent.parent)); |
| 429 | |
| 430 | return RT_EOK; |
| 431 | } |
| 432 | RTM_EXPORT(rt_sem_detach); |
| 433 | |
| 434 | #ifdef RT_USING_HEAP |