* @brief This function will iterate through each object from object * container. * * @param type is the type of object * @param iter is the iterator * @param data is the specified data passed to iterator * * @return RT_EOK on succeed, otherwise the error from `iter` * * @note this function shall not be invoked in interrupt status. */
| 634 | * @note this function shall not be invoked in interrupt status. |
| 635 | */ |
| 636 | rt_err_t rt_object_for_each(rt_uint8_t type, rt_object_iter_t iter, void *data) |
| 637 | { |
| 638 | struct rt_object *object = RT_NULL; |
| 639 | struct rt_list_node *node = RT_NULL; |
| 640 | struct rt_object_information *information = RT_NULL; |
| 641 | rt_base_t level; |
| 642 | rt_err_t error; |
| 643 | |
| 644 | information = rt_object_get_information((enum rt_object_class_type)type); |
| 645 | |
| 646 | /* parameter check */ |
| 647 | if (information == RT_NULL) |
| 648 | { |
| 649 | return -RT_EINVAL; |
| 650 | } |
| 651 | |
| 652 | /* which is invoke in interrupt status */ |
| 653 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 654 | |
| 655 | /* enter critical */ |
| 656 | level = rt_spin_lock_irqsave(&(information->spinlock)); |
| 657 | |
| 658 | /* try to find object */ |
| 659 | rt_list_for_each(node, &(information->object_list)) |
| 660 | { |
| 661 | object = rt_list_entry(node, struct rt_object, list); |
| 662 | if ((error = iter(object, data)) != RT_EOK) |
| 663 | { |
| 664 | rt_spin_unlock_irqrestore(&(information->spinlock), level); |
| 665 | |
| 666 | return error >= 0 ? RT_EOK : error; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | rt_spin_unlock_irqrestore(&(information->spinlock), level); |
| 671 | |
| 672 | return RT_EOK; |
| 673 | } |
| 674 | |
| 675 | struct _obj_find_param |
| 676 | { |
no test coverage detected