RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ Messagequeue 的协作图:

结构体

struct  rt_messagequeue
 
struct  rt_mq_message
 

宏定义

#define RT_MQ_BUF_SIZE(msg_size, max_msgs)
 

类型定义

typedef struct rt_messagequeuert_mq_t
 

函数

rt_err_t rt_mq_init (rt_mq_t mq, const char *name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag)
 
 RTM_EXPORT (rt_mq_init)
 
rt_err_t rt_mq_detach (rt_mq_t mq)
 
 RTM_EXPORT (rt_mq_detach)
 
rt_mq_t rt_mq_create (const char *name, rt_size_t msg_size, rt_size_t max_msgs, rt_uint8_t flag)
 
 RTM_EXPORT (rt_mq_create)
 
rt_err_t rt_mq_delete (rt_mq_t mq)
 
 RTM_EXPORT (rt_mq_delete)
 
rt_err_t rt_mq_send_wait (rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
 
 RTM_EXPORT (rt_mq_send_wait)
 
rt_err_t rt_mq_send_wait_interruptible (rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
 
 RTM_EXPORT (rt_mq_send_wait_interruptible)
 
rt_err_t rt_mq_send_wait_killable (rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
 
 RTM_EXPORT (rt_mq_send_wait_killable)
 
rt_err_t rt_mq_send (rt_mq_t mq, const void *buffer, rt_size_t size)
 
 RTM_EXPORT (rt_mq_send)
 
rt_err_t rt_mq_send_interruptible (rt_mq_t mq, const void *buffer, rt_size_t size)
 
 RTM_EXPORT (rt_mq_send_interruptible)
 
rt_err_t rt_mq_send_killable (rt_mq_t mq, const void *buffer, rt_size_t size)
 
 RTM_EXPORT (rt_mq_send_killable)
 
rt_err_t rt_mq_urgent (rt_mq_t mq, const void *buffer, rt_size_t size)
 
 RTM_EXPORT (rt_mq_urgent)
 
rt_ssize_t rt_mq_recv (rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout)
 
 RTM_EXPORT (rt_mq_recv)
 
rt_ssize_t rt_mq_recv_interruptible (rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout)
 
 RTM_EXPORT (rt_mq_recv_interruptible)
 
rt_ssize_t rt_mq_recv_killable (rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout)
 
 RTM_EXPORT (rt_mq_recv_killable)
 
rt_err_t rt_mq_control (rt_mq_t mq, int cmd, void *arg)
 
 RTM_EXPORT (rt_mq_control)
 

详细描述

宏定义说明

◆ RT_MQ_BUF_SIZE

#define RT_MQ_BUF_SIZE ( msg_size,
max_msgs )
值:
((RT_ALIGN((msg_size), RT_ALIGN_SIZE) + sizeof(struct rt_mq_message)) * (max_msgs))
#define RT_ALIGN(size, align)

在文件 rtthread.h574 行定义.

574#define RT_MQ_BUF_SIZE(msg_size, max_msgs) \
575((RT_ALIGN((msg_size), RT_ALIGN_SIZE) + sizeof(struct rt_mq_message)) * (max_msgs))

类型定义说明

◆ rt_mq_t

typedef struct rt_messagequeue* rt_mq_t

在文件 rtdef.h1126 行定义.

函数说明

◆ rt_mq_init()

rt_err_t rt_mq_init ( rt_mq_t mq,
const char * name,
void * msgpool,
rt_size_t msg_size,
rt_size_t pool_size,
rt_uint8_t flag )

Initialize a static messagequeue object.

注解
For the static messagequeue object, its memory space is allocated by the compiler during compiling, and shall placed on the read-write data segment or on the uninitialized data segment. By contrast, the rt_mq_create() function will allocate memory space automatically and initialize the messagequeue.
参见
rt_mq_create()
参数
mqis a pointer to the messagequeue to initialize. It is assumed that storage for the messagequeue will be allocated in your application.
nameis a pointer to the name that given to the messagequeue.
msgpoolis a pointer to the starting address of the memory space you allocated for the messagequeue in advance. In other words, msgpool is a pointer to the messagequeue buffer of the starting address.
msg_sizeis the maximum length of a message in the messagequeue (Unit: Byte).
pool_sizeis the size of the memory space allocated for the messagequeue in advance.
flagis the messagequeue flag, which determines the queuing way of how multiple threads wait when the messagequeue is not available. The messagequeue flag can be ONE of the following values:
RT_IPC_FLAG_PRIO          The pending threads will queue in order of priority.

RT_IPC_FLAG_FIFO          The pending threads will queue in the first-in-first-out method
                          (also known as first-come-first-served (FCFS) scheduling strategy).

NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to
use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
the first-in-first-out principle, and you clearly understand that all threads involved in
this messagequeue will become non-real-time threads.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. If the return value is any other values, it represents the initialization failed.
警告
This function can ONLY be called from threads.

在文件 ipc.c3092 行定义.

3098{
3099 struct rt_mq_message *head;
3100 rt_base_t temp;
3101 register rt_size_t msg_align_size;
3102
3103 /* parameter check */
3104 RT_ASSERT(mq != RT_NULL);
3105 RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
3106
3107 /* initialize object */
3109
3110 /* set parent flag */
3111 mq->parent.parent.flag = flag;
3112
3113 /* initialize ipc object */
3114 _ipc_object_init(&(mq->parent));
3115
3116 /* set message pool */
3117 mq->msg_pool = msgpool;
3118
3119 /* get correct message size */
3120 msg_align_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
3121 mq->msg_size = msg_size;
3122 mq->max_msgs = pool_size / (msg_align_size + sizeof(struct rt_mq_message));
3123
3124 if (0 == mq->max_msgs)
3125 {
3126 return -RT_EINVAL;
3127 }
3128
3129 /* initialize message list */
3130 mq->msg_queue_head = RT_NULL;
3131 mq->msg_queue_tail = RT_NULL;
3132
3133 /* initialize message empty list */
3134 mq->msg_queue_free = RT_NULL;
3135 for (temp = 0; temp < mq->max_msgs; temp ++)
3136 {
3137 head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool +
3138 temp * (msg_align_size + sizeof(struct rt_mq_message)));
3139 head->next = (struct rt_mq_message *)mq->msg_queue_free;
3140 mq->msg_queue_free = head;
3141 }
3142
3143 /* the initial entry is zero */
3144 mq->entry = 0;
3145
3146 /* initialize an additional list of sender suspend thread */
3149
3150 return RT_EOK;
3151}
#define RT_IPC_FLAG_FIFO
#define RT_IPC_FLAG_PRIO
rt_inline rt_err_t _ipc_object_init(struct rt_ipc_object *ipc)
This function will initialize an IPC object, such as semaphore, mutex, messagequeue and mailbox.
定义 ipc.c:82
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name)
This function will initialize an object and add it to object system management.
@ RT_Object_Class_MessageQueue
#define RT_ASSERT(EX)
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
rt_int32_t rt_base_t
unsigned char rt_uint8_t
rt_ubase_t rt_size_t
#define RT_NULL
struct rt_object parent
struct rt_ipc_object parent
rt_list_t suspend_sender_thread
rt_uint16_t msg_size
rt_uint16_t max_msgs
rt_uint16_t entry
struct rt_spinlock spinlock
struct rt_mq_message * next
rt_uint8_t flag

引用了 _ipc_object_init(), rt_messagequeue::entry, rt_object::flag, rt_messagequeue::max_msgs, rt_messagequeue::msg_pool, rt_messagequeue::msg_queue_free, rt_messagequeue::msg_queue_head, rt_messagequeue::msg_queue_tail, rt_messagequeue::msg_size, rt_mq_message::next, rt_ipc_object::parent, rt_messagequeue::parent, RT_ALIGN, RT_ASSERT, RT_IPC_FLAG_FIFO, RT_IPC_FLAG_PRIO, rt_list_init(), RT_NULL, RT_Object_Class_MessageQueue, rt_object_init(), rt_spin_lock_init(), rt_messagequeue::spinlock , 以及 rt_messagequeue::suspend_sender_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [1/15]

RTM_EXPORT ( rt_mq_init )

引用了 rt_mq_init().

+ 函数调用图:

◆ rt_mq_detach()

rt_err_t rt_mq_detach ( rt_mq_t mq)

This function will detach a static messagequeue object.

注解
This function is used to detach a static messagequeue object which is initialized by rt_mq_init() function. By contrast, the rt_mq_delete() function will delete a messagequeue object. When the messagequeue is successfully detached, it will resume all suspended threads in the messagequeue list.
参见
rt_mq_delete()
参数
mqis a pointer to a messagequeue object to be detached.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. If the return value is any other values, it means that the messagequeue detach failed.
警告
This function can ONLY detach a static messagequeue initialized by the rt_mq_init() function. If the messagequeue is created by the rt_mq_create() function, you MUST NOT USE this function to detach it, and ONLY USE the rt_mq_delete() function to complete the deletion.

在文件 ipc.c3173 行定义.

3174{
3175 rt_base_t level;
3176
3177 /* parameter check */
3178 RT_ASSERT(mq != RT_NULL);
3181
3182 level = rt_spin_lock_irqsave(&(mq->spinlock));
3183 /* resume all suspended thread */
3185 /* also resume all message queue private suspended thread */
3187 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
3188
3189 /* detach message queue object */
3191
3192 return RT_EOK;
3193}
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
This function will disable the local interrupt and then lock the spinlock, will lock the thread sched...
rt_err_t rt_susp_list_resume_all(rt_list_t *susp_list, rt_err_t thread_error)
This function will resume all suspended threads in the IPC object list, including the suspended list ...
定义 ipc.c:165
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
This function will unlock the spinlock and then restore current cpu interrupt status,...
rt_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.
rt_uint8_t rt_object_get_type(rt_object_t object)
This function will return the type of object without RT_Object_Class_Static flag.
void rt_object_detach(rt_object_t object)
This function will detach a static object from object system, and the memory of static object is not ...
rt_list_t suspend_thread

引用了 rt_ipc_object::parent, rt_messagequeue::parent, RT_ASSERT, RT_NULL, RT_Object_Class_MessageQueue, rt_object_detach(), rt_object_get_type(), rt_object_is_systemobject(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_susp_list_resume_all(), rt_messagequeue::spinlock, rt_messagequeue::suspend_sender_thread , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [2/15]

RTM_EXPORT ( rt_mq_detach )

引用了 rt_mq_detach().

+ 函数调用图:

◆ rt_mq_create()

rt_mq_t rt_mq_create ( const char * name,
rt_size_t msg_size,
rt_size_t max_msgs,
rt_uint8_t flag )

Creating a messagequeue object.

注解
For the messagequeue object, its memory space is allocated automatically. By contrast, the rt_mq_init() function will initialize a static messagequeue object.
参见
rt_mq_init()
参数
nameis a pointer that given to the messagequeue.
msg_sizeis the maximum length of a message in the messagequeue (Unit: Byte).
max_msgsis the maximum number of messages in the messagequeue.
flagis the messagequeue flag, which determines the queuing way of how multiple threads wait when the messagequeue is not available. The messagequeue flag can be ONE of the following values:
RT_IPC_FLAG_PRIO          The pending threads will queue in order of priority.

RT_IPC_FLAG_FIFO          The pending threads will queue in the first-in-first-out method
                          (also known as first-come-first-served (FCFS) scheduling strategy).

NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to
use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
the first-in-first-out principle, and you clearly understand that all threads involved in
this messagequeue will become non-real-time threads.
返回
Return a pointer to the messagequeue object. When the return value is RT_NULL, it means the creation failed.
警告
This function can NOT be called in interrupt context. You can use macor RT_DEBUG_NOT_IN_INTERRUPT to check it.

在文件 ipc.c3229 行定义.

3233{
3234 struct rt_messagequeue *mq;
3235 struct rt_mq_message *head;
3236 rt_base_t temp;
3237 register rt_size_t msg_align_size;
3238
3239 RT_ASSERT((flag == RT_IPC_FLAG_FIFO) || (flag == RT_IPC_FLAG_PRIO));
3240
3242
3243 /* allocate object */
3245 if (mq == RT_NULL)
3246 return mq;
3247
3248 /* set parent */
3249 mq->parent.parent.flag = flag;
3250
3251 /* initialize ipc object */
3252 _ipc_object_init(&(mq->parent));
3253
3254 /* initialize message queue */
3255
3256 /* get correct message size */
3257 msg_align_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
3258 mq->msg_size = msg_size;
3259 mq->max_msgs = max_msgs;
3260
3261 /* allocate message pool */
3262 mq->msg_pool = RT_KERNEL_MALLOC((msg_align_size + sizeof(struct rt_mq_message)) * mq->max_msgs);
3263 if (mq->msg_pool == RT_NULL)
3264 {
3266
3267 return RT_NULL;
3268 }
3269
3270 /* initialize message list */
3271 mq->msg_queue_head = RT_NULL;
3272 mq->msg_queue_tail = RT_NULL;
3273
3274 /* initialize message empty list */
3275 mq->msg_queue_free = RT_NULL;
3276 for (temp = 0; temp < mq->max_msgs; temp ++)
3277 {
3278 head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool +
3279 temp * (msg_align_size + sizeof(struct rt_mq_message)));
3280 head->next = (struct rt_mq_message *)mq->msg_queue_free;
3281 mq->msg_queue_free = head;
3282 }
3283
3284 /* the initial entry is zero */
3285 mq->entry = 0;
3286
3287 /* initialize an additional list of sender suspend thread */
3290
3291 return mq;
3292}
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
This function will allocate an object from object system.
#define RT_DEBUG_NOT_IN_INTERRUPT
struct rt_messagequeue * rt_mq_t
#define RT_KERNEL_MALLOC(sz)

引用了 _ipc_object_init(), rt_messagequeue::entry, rt_object::flag, rt_messagequeue::max_msgs, rt_messagequeue::msg_pool, rt_messagequeue::msg_queue_free, rt_messagequeue::msg_queue_head, rt_messagequeue::msg_queue_tail, rt_messagequeue::msg_size, rt_mq_message::next, rt_ipc_object::parent, rt_messagequeue::parent, RT_ALIGN, RT_ASSERT, RT_DEBUG_NOT_IN_INTERRUPT, RT_IPC_FLAG_FIFO, RT_IPC_FLAG_PRIO, RT_KERNEL_MALLOC, rt_list_init(), RT_NULL, rt_object_allocate(), RT_Object_Class_MessageQueue, rt_object_delete(), rt_spin_lock_init(), rt_messagequeue::spinlock , 以及 rt_messagequeue::suspend_sender_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [3/15]

RTM_EXPORT ( rt_mq_create )

引用了 rt_mq_create().

+ 函数调用图:

◆ rt_mq_delete()

rt_err_t rt_mq_delete ( rt_mq_t mq)

This function will delete a messagequeue object and release the memory.

注解
This function is used to delete a messagequeue object which is created by the rt_mq_create() function. By contrast, the rt_mq_detach() function will detach a static messagequeue object. When the messagequeue is successfully deleted, it will resume all suspended threads in the messagequeue list.
参见
rt_mq_detach()
参数
mqis a pointer to a messagequeue object to be deleted.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the messagequeue detach failed.
警告
This function can ONLY delete a messagequeue initialized by the rt_mq_create() function. If the messagequeue is initialized by the rt_mq_init() function, you MUST NOT USE this function to delete it, ONLY USE the rt_mq_detach() function to complete the detachment. for example,the rt_mq_create() function, it cannot be called in interrupt context.

在文件 ipc.c3315 行定义.

3316{
3317 /* parameter check */
3318 RT_ASSERT(mq != RT_NULL);
3321
3323
3324 rt_spin_lock(&(mq->spinlock));
3325 /* resume all suspended thread */
3327 /* also resume all message queue private suspended thread */
3329
3330 rt_spin_unlock(&(mq->spinlock));
3331
3332 /* free message queue pool */
3334
3335 /* delete message queue object */
3337
3338 return RT_EOK;
3339}
void rt_spin_lock(struct rt_spinlock *lock)
This function will lock the spinlock, will lock the thread scheduler.
void rt_spin_unlock(struct rt_spinlock *lock)
This function will unlock the spinlock, will unlock the thread scheduler.
#define RT_KERNEL_FREE(ptr)
#define RT_FALSE

引用了 rt_messagequeue::msg_pool, rt_ipc_object::parent, rt_messagequeue::parent, RT_ASSERT, RT_DEBUG_NOT_IN_INTERRUPT, RT_FALSE, RT_KERNEL_FREE, RT_NULL, RT_Object_Class_MessageQueue, rt_object_delete(), rt_object_get_type(), rt_object_is_systemobject(), rt_spin_lock(), rt_spin_unlock(), rt_susp_list_resume_all(), rt_messagequeue::spinlock, rt_messagequeue::suspend_sender_thread , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [4/15]

RTM_EXPORT ( rt_mq_delete )

引用了 rt_mq_delete(), RT_NULL , 以及 RT_Object_Class_MessageQueue.

+ 函数调用图:

◆ rt_mq_send_wait()

rt_err_t rt_mq_send_wait ( rt_mq_t mq,
const void * buffer,
rt_size_t size,
rt_int32_t timeout )

在文件 ipc.c3568 行定义.

3572{
3573 return _rt_mq_send_wait(mq, buffer, size, 0, timeout, RT_UNINTERRUPTIBLE);
3574}
@ RT_UNINTERRUPTIBLE

引用了 RT_UNINTERRUPTIBLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [5/15]

RTM_EXPORT ( rt_mq_send_wait )

引用了 rt_mq_send_wait().

+ 函数调用图:

◆ rt_mq_send_wait_interruptible()

rt_err_t rt_mq_send_wait_interruptible ( rt_mq_t mq,
const void * buffer,
rt_size_t size,
rt_int32_t timeout )

在文件 ipc.c3577 行定义.

3581{
3582 return _rt_mq_send_wait(mq, buffer, size, 0, timeout, RT_INTERRUPTIBLE);
3583}
@ RT_INTERRUPTIBLE

引用了 RT_INTERRUPTIBLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [6/15]

引用了 rt_mq_send_wait_interruptible().

+ 函数调用图:

◆ rt_mq_send_wait_killable()

rt_err_t rt_mq_send_wait_killable ( rt_mq_t mq,
const void * buffer,
rt_size_t size,
rt_int32_t timeout )

在文件 ipc.c3586 行定义.

3590{
3591 return _rt_mq_send_wait(mq, buffer, size, 0, timeout, RT_KILLABLE);
3592}
@ RT_KILLABLE

引用了 RT_KILLABLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [7/15]

RTM_EXPORT ( rt_mq_send_wait_killable )

引用了 rt_mq_send_wait_killable().

+ 函数调用图:

◆ rt_mq_send()

rt_err_t rt_mq_send ( rt_mq_t mq,
const void * buffer,
rt_size_t size )

This function will send a message to the messagequeue object. If there is a thread suspended on the messagequeue, the thread will be resumed.

注解
When using this function to send a message, if the messagequeue is fully used, the current thread will wait for a timeout. By contrast, when the messagequeue is fully used, the rt_mq_send_wait() function will return an error code immediately without waiting.
参见
rt_mq_send_wait()
参数
mqis a pointer to the messagequeue object to be sent.
bufferis the content of the message.
sizeis the length of the message(Unit: Byte).
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the messagequeue detach failed.
警告
This function can be called in interrupt context and thread context.

在文件 ipc.c3616 行定义.

3617{
3618 return rt_mq_send_wait(mq, buffer, size, 0);
3619}
rt_err_t rt_mq_send_wait(rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
定义 ipc.c:3568

引用了 rt_mq_send_wait().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [8/15]

RTM_EXPORT ( rt_mq_send )

引用了 rt_mq_send().

+ 函数调用图:

◆ rt_mq_send_interruptible()

rt_err_t rt_mq_send_interruptible ( rt_mq_t mq,
const void * buffer,
rt_size_t size )

在文件 ipc.c3622 行定义.

3623{
3624 return rt_mq_send_wait_interruptible(mq, buffer, size, 0);
3625}
rt_err_t rt_mq_send_wait_interruptible(rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
定义 ipc.c:3577

引用了 rt_mq_send_wait_interruptible().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [9/15]

RTM_EXPORT ( rt_mq_send_interruptible )

引用了 rt_mq_send_interruptible().

+ 函数调用图:

◆ rt_mq_send_killable()

rt_err_t rt_mq_send_killable ( rt_mq_t mq,
const void * buffer,
rt_size_t size )

在文件 ipc.c3628 行定义.

3629{
3630 return rt_mq_send_wait_killable(mq, buffer, size, 0);
3631}
rt_err_t rt_mq_send_wait_killable(rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
定义 ipc.c:3586

引用了 rt_mq_send_wait_killable().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [10/15]

RTM_EXPORT ( rt_mq_send_killable )

引用了 rt_mq_send_killable().

+ 函数调用图:

◆ rt_mq_urgent()

rt_err_t rt_mq_urgent ( rt_mq_t mq,
const void * buffer,
rt_size_t size )

This function will send an urgent message to the messagequeue object.

注解
This function is almost the same as the rt_mq_send() function. The only difference is that when sending an urgent message, the message is placed at the head of the messagequeue so that the recipient can receive the urgent message first.
参见
rt_mq_send()
参数
mqis a pointer to the messagequeue object to be sent.
bufferis the content of the message.
sizeis the length of the message(Unit: Byte).
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the mailbox detach failed.

在文件 ipc.c3651 行定义.

3652{
3653 rt_base_t level;
3654 struct rt_mq_message *msg;
3655
3656 /* parameter check */
3657 RT_ASSERT(mq != RT_NULL);
3659 RT_ASSERT(buffer != RT_NULL);
3660 RT_ASSERT(size != 0);
3661
3662 /* greater than one message size */
3663 if (size > mq->msg_size)
3664 return -RT_ERROR;
3665
3666 RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mq->parent.parent)));
3667
3668 level = rt_spin_lock_irqsave(&(mq->spinlock));
3669
3670 /* get a free list, there must be an empty item */
3671 msg = (struct rt_mq_message *)mq->msg_queue_free;
3672 /* message queue is full */
3673 if (msg == RT_NULL)
3674 {
3675 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
3676
3677 return -RT_EFULL;
3678 }
3679 /* move free list pointer */
3680 mq->msg_queue_free = msg->next;
3681
3682 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
3683
3684 /* add the length */
3685 ((struct rt_mq_message *)msg)->length = size;
3686 /* copy buffer */
3687 rt_memcpy(GET_MESSAGEBYTE_ADDR(msg), buffer, size);
3688
3689 level = rt_spin_lock_irqsave(&(mq->spinlock));
3690
3691 /* link msg to the beginning of message queue */
3692 msg->next = (struct rt_mq_message *)mq->msg_queue_head;
3693 mq->msg_queue_head = msg;
3694
3695 /* if there is no tail */
3696 if (mq->msg_queue_tail == RT_NULL)
3697 mq->msg_queue_tail = msg;
3698
3699 if(mq->entry < RT_MQ_ENTRY_MAX)
3700 {
3701 /* increase message entry */
3702 mq->entry ++;
3703 }
3704 else
3705 {
3706 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
3707 return -RT_EFULL; /* value overflowed */
3708 }
3709
3710 /* resume suspended thread */
3712 {
3714
3715 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
3716
3717 rt_schedule();
3718
3719 return RT_EOK;
3720 }
3721
3722 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
3723
3724 return RT_EOK;
3725}
struct rt_thread * rt_susp_list_dequeue(rt_list_t *susp_list, rt_err_t thread_error)
Dequeue a thread from suspended list and set it to ready. The 2 are taken as an atomic operation,...
定义 ipc.c:105
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
void rt_schedule(void)
This function will perform one scheduling. It will select one thread with the highest priority level ...
#define GET_MESSAGEBYTE_ADDR(msg)
定义 ipc.c:58
#define RT_MQ_ENTRY_MAX
rt_ssize_t length

引用了 rt_messagequeue::entry, GET_MESSAGEBYTE_ADDR, rt_mq_message::length, rt_messagequeue::msg_queue_free, rt_messagequeue::msg_queue_head, rt_messagequeue::msg_queue_tail, rt_messagequeue::msg_size, rt_mq_message::next, rt_ipc_object::parent, rt_messagequeue::parent, RT_ASSERT, rt_list_isempty(), RT_MQ_ENTRY_MAX, RT_NULL, RT_Object_Class_MessageQueue, rt_object_get_type(), RT_OBJECT_HOOK_CALL, rt_schedule(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_susp_list_dequeue(), rt_messagequeue::spinlock , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [11/15]

RTM_EXPORT ( rt_mq_urgent )

引用了 rt_mq_urgent(), RT_NULL , 以及 RT_Object_Class_MessageQueue.

+ 函数调用图:

◆ rt_mq_recv()

rt_ssize_t rt_mq_recv ( rt_mq_t mq,
void * buffer,
rt_size_t size,
rt_int32_t timeout )

在文件 ipc.c3920 行定义.

3924{
3925 return _rt_mq_recv(mq, buffer, size, 0, timeout, RT_UNINTERRUPTIBLE);
3926}

引用了 RT_UNINTERRUPTIBLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [12/15]

RTM_EXPORT ( rt_mq_recv )

引用了 rt_mq_recv().

+ 函数调用图:

◆ rt_mq_recv_interruptible()

rt_ssize_t rt_mq_recv_interruptible ( rt_mq_t mq,
void * buffer,
rt_size_t size,
rt_int32_t timeout )

在文件 ipc.c3929 行定义.

3933{
3934 return _rt_mq_recv(mq, buffer, size, 0, timeout, RT_INTERRUPTIBLE);
3935}

引用了 RT_INTERRUPTIBLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [13/15]

RTM_EXPORT ( rt_mq_recv_interruptible )

引用了 rt_mq_recv_interruptible().

+ 函数调用图:

◆ rt_mq_recv_killable()

rt_ssize_t rt_mq_recv_killable ( rt_mq_t mq,
void * buffer,
rt_size_t size,
rt_int32_t timeout )

在文件 ipc.c3938 行定义.

3942{
3943 return _rt_mq_recv(mq, buffer, size, 0, timeout, RT_KILLABLE);
3944}

引用了 RT_KILLABLE.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [14/15]

RTM_EXPORT ( rt_mq_recv_killable )

引用了 rt_mq_recv_killable().

+ 函数调用图:

◆ rt_mq_control()

rt_err_t rt_mq_control ( rt_mq_t mq,
int cmd,
void * arg )

This function will set some extra attributions of a messagequeue object.

注解
Currently this function only supports the RT_IPC_CMD_RESET command to reset the messagequeue.
参数
mqis a pointer to a messagequeue object.
cmdis a command used to configure some attributions of the messagequeue.
argis the argument of the function to execute the command.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that this function failed to execute.

在文件 ipc.c3980 行定义.

3981{
3982 rt_base_t level;
3983 struct rt_mq_message *msg;
3984
3985 RT_UNUSED(arg);
3986
3987 /* parameter check */
3988 RT_ASSERT(mq != RT_NULL);
3990
3991 if (cmd == RT_IPC_CMD_RESET)
3992 {
3993 level = rt_spin_lock_irqsave(&(mq->spinlock));
3994
3995 /* resume all waiting thread */
3997 /* also resume all message queue private suspended thread */
3999
4000 /* release all message in the queue */
4001 while (mq->msg_queue_head != RT_NULL)
4002 {
4003 /* get message from queue */
4004 msg = (struct rt_mq_message *)mq->msg_queue_head;
4005
4006 /* move message queue head */
4007 mq->msg_queue_head = msg->next;
4008 /* reach queue tail, set to NULL */
4009 if (mq->msg_queue_tail == msg)
4010 mq->msg_queue_tail = RT_NULL;
4011
4012 /* put message to free list */
4013 msg->next = (struct rt_mq_message *)mq->msg_queue_free;
4014 mq->msg_queue_free = msg;
4015 }
4016
4017 /* clean entry */
4018 mq->entry = 0;
4019
4020 rt_spin_unlock_irqrestore(&(mq->spinlock), level);
4021
4022 rt_schedule();
4023
4024 return RT_EOK;
4025 }
4026
4027 return -RT_ERROR;
4028}
#define RT_IPC_CMD_RESET
#define RT_UNUSED(x)

引用了 rt_messagequeue::entry, rt_messagequeue::msg_queue_free, rt_messagequeue::msg_queue_head, rt_messagequeue::msg_queue_tail, rt_mq_message::next, rt_ipc_object::parent, rt_messagequeue::parent, RT_ASSERT, RT_IPC_CMD_RESET, RT_NULL, RT_Object_Class_MessageQueue, rt_object_get_type(), rt_schedule(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_susp_list_resume_all(), RT_UNUSED, rt_messagequeue::spinlock, rt_messagequeue::suspend_sender_thread , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [15/15]

RTM_EXPORT ( rt_mq_control )

引用了 rt_mq_control().

+ 函数调用图: