* @brief This function will set some extra attributions of a messagequeue object. * * @note Currently this function only supports the RT_IPC_CMD_RESET command to reset the messagequeue. * * @param mq is a pointer to a messagequeue object. * * @param cmd is a command used to configure some attributions of the messagequeue. * * @param arg is the argument of the function to ex
| 3985 | * If the return value is any other values, it means that this function failed to execute. |
| 3986 | */ |
| 3987 | rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) |
| 3988 | { |
| 3989 | rt_base_t level; |
| 3990 | struct rt_mq_message *msg; |
| 3991 | |
| 3992 | RT_UNUSED(arg); |
| 3993 | |
| 3994 | /* parameter check */ |
| 3995 | RT_ASSERT(mq != RT_NULL); |
| 3996 | RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue); |
| 3997 | |
| 3998 | if (cmd == RT_IPC_CMD_RESET) |
| 3999 | { |
| 4000 | level = rt_spin_lock_irqsave(&(mq->spinlock)); |
| 4001 | |
| 4002 | /* resume all waiting thread */ |
| 4003 | rt_susp_list_resume_all(&mq->parent.suspend_thread, RT_ERROR); |
| 4004 | /* also resume all message queue private suspended thread */ |
| 4005 | rt_susp_list_resume_all(&(mq->suspend_sender_thread), RT_ERROR); |
| 4006 | |
| 4007 | /* release all message in the queue */ |
| 4008 | while (mq->msg_queue_head != RT_NULL) |
| 4009 | { |
| 4010 | /* get message from queue */ |
| 4011 | msg = (struct rt_mq_message *)mq->msg_queue_head; |
| 4012 | |
| 4013 | /* move message queue head */ |
| 4014 | mq->msg_queue_head = msg->next; |
| 4015 | /* reach queue tail, set to NULL */ |
| 4016 | if (mq->msg_queue_tail == msg) |
| 4017 | mq->msg_queue_tail = RT_NULL; |
| 4018 | |
| 4019 | /* put message to free list */ |
| 4020 | msg->next = (struct rt_mq_message *)mq->msg_queue_free; |
| 4021 | mq->msg_queue_free = msg; |
| 4022 | } |
| 4023 | |
| 4024 | /* clean entry */ |
| 4025 | mq->entry = 0; |
| 4026 | |
| 4027 | rt_spin_unlock_irqrestore(&(mq->spinlock), level); |
| 4028 | |
| 4029 | rt_schedule(); |
| 4030 | |
| 4031 | return RT_EOK; |
| 4032 | } |
| 4033 | |
| 4034 | return -RT_ERROR; |
| 4035 | } |
| 4036 | RTM_EXPORT(rt_mq_control); |
| 4037 | |
| 4038 | /**@}*/ |
no test coverage detected