* @brief This function will delete a timer and release timer memory * * @param timer the timer to be deleted * * @return the operation status, RT_EOK on OK; -RT_ERROR on error */
| 375 | * @return the operation status, RT_EOK on OK; -RT_ERROR on error |
| 376 | */ |
| 377 | rt_err_t rt_timer_delete(rt_timer_t timer) |
| 378 | { |
| 379 | rt_base_t level; |
| 380 | struct rt_spinlock *spinlock; |
| 381 | |
| 382 | /* parameter check */ |
| 383 | RT_ASSERT(timer != RT_NULL); |
| 384 | RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); |
| 385 | RT_ASSERT(rt_object_is_systemobject(&timer->parent) == RT_FALSE); |
| 386 | |
| 387 | spinlock = _timerlock_idx(timer); |
| 388 | |
| 389 | level = rt_spin_lock_irqsave(spinlock); |
| 390 | |
| 391 | _timer_remove(timer); |
| 392 | /* stop timer */ |
| 393 | timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; |
| 394 | rt_spin_unlock_irqrestore(spinlock, level); |
| 395 | rt_object_delete(&(timer->parent)); |
| 396 | |
| 397 | return RT_EOK; |
| 398 | } |
| 399 | RTM_EXPORT(rt_timer_delete); |
| 400 | #endif /* RT_USING_HEAP */ |
| 401 |