* @brief This function will send an urgent mail to the mailbox object. * * @note This function is almost the same as the rt_mb_send() function. The only difference is that * when sending an urgent mail, the mail will be placed at the head of the mail queue so that * the recipient can receive the urgent mail first. * * @see rt_mb_send() * * @param mb is a
| 2770 | * If the return value is any other values, it means that the mailbox detach failed. |
| 2771 | */ |
| 2772 | rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) |
| 2773 | { |
| 2774 | rt_base_t level; |
| 2775 | |
| 2776 | /* parameter check */ |
| 2777 | RT_ASSERT(mb != RT_NULL); |
| 2778 | RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox); |
| 2779 | |
| 2780 | RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mb->parent.parent))); |
| 2781 | |
| 2782 | level = rt_spin_lock_irqsave(&(mb->spinlock)); |
| 2783 | |
| 2784 | if (mb->entry == mb->size) |
| 2785 | { |
| 2786 | rt_spin_unlock_irqrestore(&(mb->spinlock), level); |
| 2787 | return -RT_EFULL; |
| 2788 | } |
| 2789 | |
| 2790 | /* rewind to the previous position */ |
| 2791 | if (mb->out_offset > 0) |
| 2792 | { |
| 2793 | mb->out_offset --; |
| 2794 | } |
| 2795 | else |
| 2796 | { |
| 2797 | mb->out_offset = mb->size - 1; |
| 2798 | } |
| 2799 | |
| 2800 | /* set ptr */ |
| 2801 | mb->msg_pool[mb->out_offset] = value; |
| 2802 | |
| 2803 | /* increase message entry */ |
| 2804 | mb->entry ++; |
| 2805 | |
| 2806 | /* resume suspended thread */ |
| 2807 | if (!rt_list_isempty(&mb->parent.suspend_thread)) |
| 2808 | { |
| 2809 | rt_susp_list_dequeue(&(mb->parent.suspend_thread), RT_EOK); |
| 2810 | |
| 2811 | rt_spin_unlock_irqrestore(&(mb->spinlock), level); |
| 2812 | |
| 2813 | rt_schedule(); |
| 2814 | |
| 2815 | return RT_EOK; |
| 2816 | } |
| 2817 | rt_spin_unlock_irqrestore(&(mb->spinlock), level); |
| 2818 | |
| 2819 | return RT_EOK; |
| 2820 | } |
| 2821 | RTM_EXPORT(rt_mb_urgent); |
| 2822 | |
| 2823 |
no test coverage detected