更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
Queue
Queue 的协作图:

结构体

struct  LosQueueCB
 
struct  tagQueueInfo
 

类型定义

typedef struct tagQueueInfo QUEUE_INFO_S
 

函数

VOID * OsQueueMailAlloc (UINT32 queueID, VOID *mailPool, UINT32 timeout)
 Alloc a stationary memory for a mail. 更多...
 
UINT32 OsQueueMailFree (UINT32 queueID, VOID *mailPool, VOID *mailMem)
 Free a stationary memory of a mail. 更多...
 
UINT32 LOS_QueueCreate (CHAR *queueName, UINT16 len, UINT32 *queueID, UINT32 flags, UINT16 maxMsgSize)
 Create a message queue. 更多...
 
UINT32 LOS_QueueReadCopy (UINT32 queueID, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
 Read a queue. 更多...
 
UINT32 LOS_QueueWriteCopy (UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
 Write data into a queue. 更多...
 
UINT32 LOS_QueueRead (UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
 Read a queue. 更多...
 
UINT32 LOS_QueueWrite (UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
 Write data into a queue. 更多...
 
UINT32 LOS_QueueWriteHead (UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
 Write data into a queue header. 更多...
 
UINT32 LOS_QueueWriteHeadCopy (UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
 Write data into a queue header. 更多...
 
UINT32 LOS_QueueDelete (UINT32 queueID)
 Delete a queue. 更多...
 
UINT32 LOS_QueueInfoGet (UINT32 queueID, QUEUE_INFO_S *queueInfo)
 Obtain queue information. 更多...
 

变量

LosQueueCBg_allQueue
 消息队列池 更多...
 

详细描述

类型定义说明

◆ QUEUE_INFO_S

typedef struct tagQueueInfo QUEUE_INFO_S

Structure of the block for queue information query

函数说明

◆ LOS_QueueCreate()

UINT32 LOS_QueueCreate ( CHAR queueName,
UINT16  len,
UINT32 queueID,
UINT32  flags,
UINT16  maxMsgSize 
)

Create a message queue.

Description:
This API is used to create a message queue.
注意
  • Threre are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessory.
参数
queueName[IN] Message queue name. Reserved parameter, not used for now.
len[IN] Queue length. The value range is [1,0xffff].
queueID[OUT] ID of the queue control structure that is successfully created.
flags[IN] Queue mode. Reserved parameter, not used for now.
maxMsgSize[IN] Node size. The value range is [1,0xffff-4].
返回值
#LOS_OKThe message queue is successfully created.
#LOS_ERRNO_QUEUE_CB_UNAVAILABLEThe upper limit of the number of created queues is exceeded.
#LOS_ERRNO_QUEUE_CREATE_NO_MEMORYInsufficient memory for queue creation.
#LOS_ERRNO_QUEUE_CREAT_PTR_NULLNull pointer, queueID is NULL.
#LOS_ERRNO_QUEUE_PARA_ISZEROThe queue length or message node size passed in during queue creation is 0.
#LOS_ERRNO_QUEUE_SIZE_TOO_BIGThe parameter usMaxMsgSize is larger than 0xffff - 4.
Dependency:
  • los_queue.h: the header file that contains the API declaration.
参见
LOS_QueueDelete

Create a message queue.

在文件 los_queue.c131 行定义.

133{
134 LosQueueCB *queueCB = NULL;
135 UINT32 intSave;
136 LOS_DL_LIST *unusedQueue = NULL;
137 UINT8 *queue = NULL;
138 UINT16 msgSize;
139
140 (VOID)queueName;
141 (VOID)flags;
142
143 if (queueID == NULL) {
144 return LOS_ERRNO_QUEUE_CREAT_PTR_NULL;
145 }
146
147 if (maxMsgSize > (OS_NULL_SHORT - sizeof(UINT32))) {// maxMsgSize上限 为啥要减去 sizeof(UINT32) ,因为前面存的是队列的大小
148 return LOS_ERRNO_QUEUE_SIZE_TOO_BIG;
149 }
150
151 if ((len == 0) || (maxMsgSize == 0)) {
152 return LOS_ERRNO_QUEUE_PARA_ISZERO;
153 }
154
155 msgSize = maxMsgSize + sizeof(UINT32);//总size = 消息体内容长度 + 消息大小(UINT32)
156 /*
157 * Memory allocation is time-consuming, to shorten the time of disable interrupt,
158 * move the memory allocation to here.
159 *///内存分配非常耗时,为了缩短禁用中断的时间,将内存分配移到此处,用的时候分配队列内存
160 queue = (UINT8 *)LOS_MemAlloc(m_aucSysMem1, (UINT32)len * msgSize);//从系统内存池中分配,由这里提供读写队列的内存
161 if (queue == NULL) {//这里是一次把队列要用到的所有最大内存都申请下来了,能保证不会出现后续使用过程中内存不够的问题出现
162 return LOS_ERRNO_QUEUE_CREATE_NO_MEMORY;//调用处有 OsSwtmrInit sys_mbox_new DoMqueueCreate ==
163 }
164
165 SCHEDULER_LOCK(intSave);
166 if (LOS_ListEmpty(&g_freeQueueList)) {//没有空余的队列ID的处理,注意软时钟定时器是由 g_swtmrCBArray统一管理的,里面有正在使用和可分配空闲的队列
167 SCHEDULER_UNLOCK(intSave);//g_freeQueueList是管理可用于分配的队列链表,申请消息队列的ID需要向它要
169 (VOID)LOS_MemFree(m_aucSysMem1, queue);//没有就要释放 queue申请的内存
170 return LOS_ERRNO_QUEUE_CB_UNAVAILABLE;
171 }
172
173 unusedQueue = LOS_DL_LIST_FIRST(&g_freeQueueList);//找到一个没有被使用的队列
174 LOS_ListDelete(unusedQueue);//将自己从g_freeQueueList中摘除, unusedQueue只是个 LOS_DL_LIST 结点.
175 queueCB = GET_QUEUE_LIST(unusedQueue);//通过unusedQueue找到整个消息队列(LosQueueCB)
176 queueCB->queueLen = len; //队列中消息的总个数,注意这个一旦创建是不能变的.
177 queueCB->queueSize = msgSize;//消息节点的大小,注意这个一旦创建也是不能变的.
178 queueCB->queueHandle = queue; //队列句柄,队列内容存储区.
179 queueCB->queueState = OS_QUEUE_INUSED; //队列状态使用中
180 queueCB->readWriteableCnt[OS_QUEUE_READ] = 0;//可读资源计数,OS_QUEUE_READ(0):可读.
181 queueCB->readWriteableCnt[OS_QUEUE_WRITE] = len;//可些资源计数 OS_QUEUE_WRITE(1):可写, 默认len可写.
182 queueCB->queueHead = 0;//队列头节点
183 queueCB->queueTail = 0;//队列尾节点
184 LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_READ]);//初始化可读队列任务链表
185 LOS_ListInit(&queueCB->readWriteList[OS_QUEUE_WRITE]);//初始化可写队列任务链表
186 LOS_ListInit(&queueCB->memList);//
187
188 OsQueueDbgUpdateHook(queueCB->queueID, OsCurrTaskGet()->taskEntry);//在创建或删除队列调试信息时更新任务条目
189 SCHEDULER_UNLOCK(intSave);
190
191 *queueID = queueCB->queueID;//带走队列ID
192 OsHookCall(LOS_HOOK_TYPE_QUEUE_CREATE, queueCB);
193 return LOS_OK;
194}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
Definition: los_list.h:321
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList
空闲队列链表,管分配的,需要队列从这里申请
Definition: los_queue.c:99
STATIC INLINE VOID OsQueueCheckHook(VOID)
STATIC INLINE VOID OsQueueDbgUpdateHook(UINT32 queueID, TSK_ENTRY_FUNC entry)
@ OS_QUEUE_WRITE
写队列
Definition: los_queue_pri.h:64
@ OS_QUEUE_READ
读队列
Definition: los_queue_pri.h:63
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
unsigned short UINT16
Definition: los_typedef.h:56
unsigned char UINT8
Definition: los_typedef.h:55
unsigned int UINT32
Definition: los_typedef.h:57
UINT16 queueHead
Definition: los_queue_pri.h:94
UINT16 readWriteableCnt[OS_QUEUE_N_RW]
Definition: los_queue_pri.h:96
UINT16 queueLen
Definition: los_queue_pri.h:91
UINT16 queueTail
Definition: los_queue_pri.h:95
LOS_DL_LIST memList
UINT16 queueSize
Definition: los_queue_pri.h:92
UINT16 queueState
Definition: los_queue_pri.h:90
UINT8 * queueHandle
Definition: los_queue_pri.h:89
UINT32 queueID
Definition: los_queue_pri.h:93
LOS_DL_LIST readWriteList[OS_QUEUE_N_RW]
Definition: los_queue_pri.h:98
函数调用图:
这是这个函数的调用关系图:

◆ LOS_QueueDelete()

UINT32 LOS_QueueDelete ( UINT32  queueID)

Delete a queue.

Description:
This API is used to delete a queue.
注意
  • This API cannot be used to delete a queue that is not created.
  • A synchronous queue fails to be deleted if any tasks are blocked on it, or some queues are being read or written.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
返回值
#LOS_OKThe queue is successfully deleted.
#LOS_ERRNO_QUEUE_NOT_FOUNDThe queue cannot be found.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue handle passed in when the queue is being deleted is incorrect.
#LOS_ERRNO_QUEUE_IN_TSKUSEThe queue that blocks a task cannot be deleted.
#LOS_ERRNO_QUEUE_IN_TSKWRITEQueue reading and writing are not synchronous.
Dependency:
  • los_queue.h: the header file that contains the API declaration.
参见
LOS_QueueCreate | LOS_QueueCreate
   外部接口 删除队列,还有任务要读/写消息时不能删除
   删除队列时,根据传入的队列ID寻找到对应的队列,把队列状态置为未使用,
   释放原队列所占的空间,对应的队列控制头置为初始状态。
* 

在文件 los_queue.c486 行定义.

487{
488 LosQueueCB *queueCB = NULL;
489 UINT8 *queue = NULL;
490 UINT32 intSave;
491 UINT32 ret;
492
493 if (GET_QUEUE_INDEX(queueID) >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {
494 return LOS_ERRNO_QUEUE_NOT_FOUND;
495 }
496
497 SCHEDULER_LOCK(intSave);
498 queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);//拿到队列实体
499 if ((queueCB->queueID != queueID) || (queueCB->queueState == OS_QUEUE_UNUSED)) {
500 ret = LOS_ERRNO_QUEUE_NOT_CREATE;
501 goto QUEUE_END;
502 }
503
504 if (!LOS_ListEmpty(&queueCB->readWriteList[OS_QUEUE_READ])) {//尚有任务要读数据
505 ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
506 goto QUEUE_END;
507 }
508
509 if (!LOS_ListEmpty(&queueCB->readWriteList[OS_QUEUE_WRITE])) {//尚有任务要写数据
510 ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
511 goto QUEUE_END;
512 }
513
514 if (!LOS_ListEmpty(&queueCB->memList)) {//
515 ret = LOS_ERRNO_QUEUE_IN_TSKUSE;
516 goto QUEUE_END;
517 }
518
520 queueCB->queueLen) {//读写队列的内容长度不等于总长度
521 ret = LOS_ERRNO_QUEUE_IN_TSKWRITE;
522 goto QUEUE_END;
523 }
524
525 queue = queueCB->queueHandle; //队列buf
526 queueCB->queueHandle = NULL; //
527 queueCB->queueState = OS_QUEUE_UNUSED;//重置队列状态
528 queueCB->queueID = SET_QUEUE_ID(GET_QUEUE_COUNT(queueCB->queueID) + 1, GET_QUEUE_INDEX(queueCB->queueID));//@note_why 这里需要这样做吗?
529 OsQueueDbgUpdateHook(queueCB->queueID, NULL);
530
531 LOS_ListTailInsert(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);//回收,将节点挂入可分配链表,等待重新被分配再利用
532 SCHEDULER_UNLOCK(intSave);
533 OsHookCall(LOS_HOOK_TYPE_QUEUE_DELETE, queueCB);
534 ret = LOS_MemFree(m_aucSysMem1, (VOID *)queue);//释放队列句柄
535 return ret;
536
537QUEUE_END:
538 SCHEDULER_UNLOCK(intSave);
539 return ret;
540}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
Definition: los_list.h:244
函数调用图:
这是这个函数的调用关系图:

◆ LOS_QueueInfoGet()

UINT32 LOS_QueueInfoGet ( UINT32  queueID,
QUEUE_INFO_S queueInfo 
)

Obtain queue information.

Description:
This API is used to obtain queue information.
注意
  • The specific queue should be created firstly.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
queueInfo[OUT] The queue information to be read must not be null.
返回值
#LOS_OKThe queue information is successfully obtained.
#LOS_ERRNO_QUEUE_PTR_NULLThe pointer to the queue information to be obtained is null.
#LOS_ERRNO_QUEUE_INVALIDThe handle of the queue that is being read is invalid.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue in which the information to be obtained is stored is not created.
Dependency:
  • los_queue.h: the header file that contains the API declaration.
参见
LOS_QueueCreate

Obtain queue information.

在文件 los_queue.c542 行定义.

543{
544 UINT32 intSave;
545 UINT32 ret = LOS_OK;
546 LosQueueCB *queueCB = NULL;
547 LosTaskCB *tskCB = NULL;
548
549 if (queueInfo == NULL) {
550 return LOS_ERRNO_QUEUE_PTR_NULL;
551 }
552
553 if (GET_QUEUE_INDEX(queueID) >= LOSCFG_BASE_IPC_QUEUE_LIMIT) {//1024
554 return LOS_ERRNO_QUEUE_INVALID;
555 }
556
557 (VOID)memset_s((VOID *)queueInfo, sizeof(QUEUE_INFO_S), 0, sizeof(QUEUE_INFO_S));//接走数据之前先清0
558 SCHEDULER_LOCK(intSave);
559
560 queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);//通过队列ID获取 QCB
561 if ((queueCB->queueID != queueID) || (queueCB->queueState == OS_QUEUE_UNUSED)) {
562 ret = LOS_ERRNO_QUEUE_NOT_CREATE;
563 goto QUEUE_END;
564 }
565
566 queueInfo->uwQueueID = queueID;
567 queueInfo->usQueueLen = queueCB->queueLen;
568 queueInfo->usQueueSize = queueCB->queueSize;
569 queueInfo->usQueueHead = queueCB->queueHead;
570 queueInfo->usQueueTail = queueCB->queueTail;
571 queueInfo->usReadableCnt = queueCB->readWriteableCnt[OS_QUEUE_READ];//可读数
572 queueInfo->usWritableCnt = queueCB->readWriteableCnt[OS_QUEUE_WRITE];//可写数
573
574 LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_READ], LosTaskCB, pendList) {//找出哪些task需要读消息
575 queueInfo->uwWaitReadTask |= 1ULL << tskCB->taskID;//记录等待读消息的任务号, uwWaitReadTask 每一位代表一个任务编号
576 }//0b..011011011 代表 0,1,3,4,6,7 号任务有数据等待读消息.
577
578 LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_WRITE], LosTaskCB, pendList) {//找出哪些task需要写消息
579 queueInfo->uwWaitWriteTask |= 1ULL << tskCB->taskID;//记录等待写消息的任务号, uwWaitWriteTask 每一位代表一个任务编号
580 }////0b..011011011 代表 0,1,3,4,6,7 号任务有数据等待写消息.
581
582 LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->memList, LosTaskCB, pendList) {//同上
583 queueInfo->uwWaitMemTask |= 1ULL << tskCB->taskID; //MailBox模块使用
584 }
585
586QUEUE_END:
587 SCHEDULER_UNLOCK(intSave);
588 return ret;
589}
struct tagQueueInfo QUEUE_INFO_S
UINT32 taskID
UINT64 uwWaitReadTask
Definition: los_queue.h:346
UINT16 usQueueTail
Definition: los_queue.h:343
UINT64 uwWaitMemTask
Definition: los_queue.h:348
UINT16 usWritableCnt
Definition: los_queue.h:344
UINT16 usQueueHead
Definition: los_queue.h:342
UINT16 usQueueSize
Definition: los_queue.h:341
UINT64 uwWaitWriteTask
Definition: los_queue.h:347
UINT32 uwQueueID
Definition: los_queue.h:339
UINT16 usQueueLen
Definition: los_queue.h:340
UINT16 usReadableCnt
Definition: los_queue.h:345
这是这个函数的调用关系图:

◆ LOS_QueueRead()

UINT32 LOS_QueueRead ( UINT32  queueID,
VOID *  bufferAddr,
UINT32  bufferSize,
UINT32  timeout 
)

Read a queue.

Description:
This API is used to read the address of data in a specified queue, and store it to the address specified by bufferAddr.
注意
  • The specific queue should be created firstly.
  • Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is read first.
  • bufferAddr stores the obtained data address.
  • Do not read or write a queue in unblocking modes such as an interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The argument timeout is a relative time.
  • The bufferSize is not really used in LOS_QueueRead, because the interface is only used to obtain the address of data.
  • The buffer which the bufferAddr pointing to must be greater than or equal to 4 bytes.
  • Do not call this API in software timer callback.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
bufferAddr[OUT] Starting address that stores the obtained data. The starting address must not be null.
bufferSize[IN] Passed-in buffer size,The value range is [sizeof(CHAR*),OS_NULL_SHORT - sizeof(UINT32)].
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
返回值
#LOS_OKThe queue is successfully read.
#LOS_ERRNO_QUEUE_INVALIDThe handle of the queue that is being read is invalid.
#LOS_ERRNO_QUEUE_READ_PTR_NULLThe pointer passed in during queue reading is null.
#LOS_ERRNO_QUEUE_READSIZE_IS_INVALIDThe buffer size passed in during queue reading is invalid.
#LOS_ERRNO_QUEUE_READ_IN_INTERRUPTThe queue cannot be read during an interrupt when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue to be read is not created.
#LOS_ERRNO_QUEUE_ISEMPTYNo resource is in the queue that is being read when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_PEND_IN_LOCKThe task is forbidden to be blocked on a queue when the task is locked.
#LOS_ERRNO_QUEUE_TIMEOUTThe time set for waiting to processing the queue expires.
Dependency:
  • los_queue.h: The header file that contains the API declaration.
参见
LOS_QueueWrite | LOS_QueueCreate
   外部接口 读一个队列数据
   读队列时,根据Head找到最先写入队列中的消息节点进行读取。如果Head已经指向队列尾则采用回卷方式。
   根据usReadableCnt判断队列是否有消息读取,对全部空闲(usReadableCnt为0)队列进行读队列操作会引起任务挂起。
* 

在文件 los_queue.c436 行定义.

437{
438 return LOS_QueueReadCopy(queueID, bufferAddr, &bufferSize, timeout);
439}
LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueID, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
接口函数定时读取消息队列
Definition: los_queue.c:377
函数调用图:
这是这个函数的调用关系图:

◆ LOS_QueueReadCopy()

UINT32 LOS_QueueReadCopy ( UINT32  queueID,
VOID *  bufferAddr,
UINT32 bufferSize,
UINT32  timeout 
)

Read a queue.

Description:
This API is used to read data in a specified queue, and store the obtained data to the address specified by bufferAddr. The address and the size of the data to be read are defined by users.
注意
  • The specific queue should be created firstly.
  • Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is read first.
  • bufferAddr stores the obtained data.
  • Do not read or write a queue in unblocking modes such as an interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The argument timeout is a relative time.
  • Do not call this API in software timer callback.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
bufferAddr[OUT] Starting address that stores the obtained data. The starting address must not be null.
bufferSize[IN/OUT] Where to maintain the buffer wanted-size before read, and the real-size after read.
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
返回值
#LOS_OKThe queue is successfully read.
#LOS_ERRNO_QUEUE_INVALIDThe handle of the queue that is being read is invalid.
#LOS_ERRNO_QUEUE_READ_PTR_NULLThe pointer passed in during queue reading is null.
#LOS_ERRNO_QUEUE_READSIZE_IS_INVALIDThe buffer size passed in during queue reading is invalid.
#LOS_ERRNO_QUEUE_READ_IN_INTERRUPTThe queue cannot be read during an interrupt when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue to be read is not created.
#LOS_ERRNO_QUEUE_ISEMPTYNo resource is in the queue that is being read when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_PEND_IN_LOCKThe task is forbidden to be blocked on a queue when the task is locked.
#LOS_ERRNO_QUEUE_TIMEOUTThe time set for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALLThe buffer size passed in during queue reading is less than the queue size.
Dependency:
  • los_queue.h: the header file that contains the API declaration.
参见
LOS_QueueWriteCopy | LOS_QueueCreate

Read a queue.

在文件 los_queue.c377 行定义.

381{
382 UINT32 ret;
383 UINT32 operateType;
384
385 ret = OsQueueReadParameterCheck(queueID, bufferAddr, bufferSize, timeout);//参数检查
386 if (ret != LOS_OK) {
387 return ret;
388 }
389
390 operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD);//从头开始读
391 return OsQueueOperate(queueID, operateType, bufferAddr, bufferSize, timeout);//定时执行读操作
392}
STATIC LITE_OS_SEC_TEXT UINT32 OsQueueReadParameterCheck(UINT32 queueID, const VOID *bufferAddr, const UINT32 *bufferSize, UINT32 timeout)
读队列参数检查
Definition: los_queue.c:196
UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
队列操作.是读是写由operateType定 本函数是消息队列最重要的一个函数,可以分析出读取消息过程中 发生的细节,涉及任务的唤醒和阻塞,阻塞链表任务的相互提醒.
Definition: los_queue.c:322
@ OS_QUEUE_HEAD
队列头部标识
Definition: los_queue_pri.h:69
函数调用图:
这是这个函数的调用关系图:

◆ LOS_QueueWrite()

UINT32 LOS_QueueWrite ( UINT32  queueID,
VOID *  bufferAddr,
UINT32  bufferSize,
UINT32  timeout 
)

Write data into a queue.

Description:
This API is used to write the address of data specified by bufferAddr into a queue.
注意
  • The specific queue should be created firstly.
  • Do not read or write a queue in unblocking modes such as an interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The address of the data of the size specified by bufferSize and stored at the address specified by bufferAddr is to be written.
  • The argument timeout is a relative time.
  • The bufferSize is not really used in LOS_QueueWrite, because the interface is only used to write the address of data specified by bufferAddr into a queue.
  • Do not call this API in software timer callback.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
bufferAddr[IN] Starting address that stores the data to be written. The starting address must not be null.
bufferSize[IN] This parameter is not in use temporarily.
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
返回值
#LOS_OKThe data is successfully written into the queue.
#LOS_ERRNO_QUEUE_INVALIDThe queue handle passed in during queue writing is invalid.
#LOS_ERRNO_QUEUE_WRITE_PTR_NULLThe pointer passed in during queue writing is null.
#LOS_ERRNO_QUEUE_WRITESIZE_ISZEROThe buffer size passed in during queue writing is 0.
#LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPTThe queue cannot be written during an interrupt when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue into which the data is written is not created.
#LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIGThe buffer size passed in during queue writing is bigger than the queue size.
#LOS_ERRNO_QUEUE_ISFULLNo free node is available during queue writing.
#LOS_ERRNO_QUEUE_PEND_IN_LOCKThe task is forbidden to be blocked on a queue when the task is locked.
#LOS_ERRNO_QUEUE_TIMEOUTThe time set for waiting to processing the queue expires.
Dependency:
  • los_queue.h: The header file that contains the API declaration.
参见
LOS_QueueRead | LOS_QueueCreate
   外部接口 写一个队列数据
   根据Tail找到被占用消息节点末尾的空闲节点作为数据写入对象。如果Tail已经指向队列尾则采用回卷方式。
   根据usWritableCnt判断队列是否可以写入,不能对已满(usWritableCnt为0)队列进行写队列操作
* 

在文件 los_queue.c449 行定义.

450{
451 if (bufferAddr == NULL) {
452 return LOS_ERRNO_QUEUE_WRITE_PTR_NULL;
453 }
454 bufferSize = sizeof(CHAR *);
455 return LOS_QueueWriteCopy(queueID, &bufferAddr, bufferSize, timeout);
456}
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
接口函数 从队列尾部开始写
Definition: los_queue.c:411
char CHAR
Definition: los_typedef.h:63
函数调用图:
这是这个函数的调用关系图:

◆ LOS_QueueWriteCopy()

UINT32 LOS_QueueWriteCopy ( UINT32  queueID,
VOID *  bufferAddr,
UINT32  bufferSize,
UINT32  timeout 
)

Write data into a queue.

Description:
This API is used to write the data of the size specified by bufferSize and stored at the address specified by bufferAddr into a queue.
注意
  • The specific queue should be created firstly.
  • Do not read or write a queue in unblocking modes such as interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The data to be written is of the size specified by bufferSize and is stored at the address specified by bufferAddr.
  • The argument timeout is a relative time.
  • Do not call this API in software timer callback.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
bufferAddr[IN] Starting address that stores the data to be written.The starting address must not be null.
bufferSize[IN] Passed-in buffer size. The value range is [1,USHRT_MAX - sizeof(UINT32)].
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
返回值
#LOS_OKThe data is successfully written into the queue.
#LOS_ERRNO_QUEUE_INVALIDThe queue handle passed in during queue writing is invalid.
#LOS_ERRNO_QUEUE_WRITE_PTR_NULLThe pointer passed in during queue writing is null.
#LOS_ERRNO_QUEUE_WRITESIZE_ISZEROThe buffer size passed in during queue writing is 0.
#LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPTThe queue cannot be written during an interrupt when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue into which the data is written is not created.
#LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIGThe buffer size passed in during queue writing is bigger than the queue size.
#LOS_ERRNO_QUEUE_ISFULLNo free node is available during queue writing.
#LOS_ERRNO_QUEUE_PEND_IN_LOCKThe task is forbidden to be blocked on a queue when the task is locked.
#LOS_ERRNO_QUEUE_TIMEOUTThe time set for waiting to processing the queue expires.
Dependency:
  • los_queue.h: the header file that contains the API declaration.
参见
LOS_QueueReadCopy | LOS_QueueCreate

Write data into a queue.

在文件 los_queue.c411 行定义.

415{
416 UINT32 ret;
417 UINT32 operateType;
418
419 ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &bufferSize, timeout);//参数检查
420 if (ret != LOS_OK) {
421 return ret;
422 }
423
424 operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL);//从尾部开始写
425 return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeout);//执行写操作
426}
STATIC LITE_OS_SEC_TEXT UINT32 OsQueueWriteParameterCheck(UINT32 queueID, const VOID *bufferAddr, const UINT32 *bufferSize, UINT32 timeout)
写队列参数检查
Definition: los_queue.c:220
@ OS_QUEUE_TAIL
队列尾部标识
Definition: los_queue_pri.h:70
函数调用图:
这是这个函数的调用关系图:

◆ LOS_QueueWriteHead()

UINT32 LOS_QueueWriteHead ( UINT32  queueID,
VOID *  bufferAddr,
UINT32  bufferSize,
UINT32  timeout 
)

Write data into a queue header.

Description:
This API is used to write the data of the size specified by bufferSize and stored at the address specified by bufferAddr into a queue header.
注意
  • Do not read or write a queue in unblocking modes such as an interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The address of the data of the size specified by bufferSize and stored at the address specified by bufferAddr is to be written.
  • The argument timeout is a relative time.
  • LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be used.
  • Do not call this API in software timer callback.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
bufferAddr[OUT] Starting address that stores the data to be written. The starting address must not be null.
bufferSize[IN] This parameter is not in use temporarily.
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
返回值
#LOS_OKThe data is successfully written into the queue.
#LOS_ERRNO_QUEUE_INVALIDThe queue handle passed in during queue writing is invalid.
#LOS_ERRNO_QUEUE_WRITE_PTR_NULLThe pointer passed in during queue writing is null.
#LOS_ERRNO_QUEUE_WRITESIZE_ISZEROThe buffer size passed in during queue writing is 0.
#LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPTThe queue cannot be written during an interrupt when the time for waiting to processing the queue expires. waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue into which the data is written is not created.
#LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIGThe buffer size passed in during queue writing is bigger than the queue size.
#LOS_ERRNO_QUEUE_ISFULLNo free node is available during queue writing.
#LOS_ERRNO_QUEUE_PEND_IN_LOCKThe task is forbidden to be blocked on a queue when the task is locked.
#LOS_ERRNO_QUEUE_TIMEOUTThe time set for waiting to processing the queue expires.
Dependency:
  • los_queue.h: The header file that contains the API declaration.
参见
LOS_QueueRead | LOS_QueueCreate
   外部接口 从头部写入
   写队列时,根据Tail找到被占用消息节点末尾的空闲节点作为数据写入对象。如果Tail已经指向队列尾则采用回卷方式。
   根据usWritableCnt判断队列是否可以写入,不能对已满(usWritableCnt为0)队列进行写队列操作
* 

在文件 los_queue.c466 行定义.

470{
471 if (bufferAddr == NULL) {
472 return LOS_ERRNO_QUEUE_WRITE_PTR_NULL;
473 }
474 bufferSize = sizeof(CHAR *);
475 return LOS_QueueWriteHeadCopy(queueID, &bufferAddr, bufferSize, timeout);
476}
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueID, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
接口函数从队列头开始写
Definition: los_queue.c:394
函数调用图:

◆ LOS_QueueWriteHeadCopy()

UINT32 LOS_QueueWriteHeadCopy ( UINT32  queueID,
VOID *  bufferAddr,
UINT32  bufferSize,
UINT32  timeout 
)

Write data into a queue header.

Description:
This API is used to write the data of the size specified by bufferSize and stored at the address specified by bufferAddr into a queue header.
注意
  • Do not read or write a queue in unblocking modes such as an interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The address of the data of the size specified by bufferSize and stored at the address specified by bufferAddr is to be written.
  • The argument timeout is a relative time.
  • LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be used.
  • Do not call this API in software timer callback.
参数
queueID[IN] Queue ID created by LOS_QueueCreate. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
bufferAddr[OUT] Starting address that stores the data to be written. The starting address must not be null.
bufferSize[IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff].
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick).
返回值
#LOS_OKThe data is successfully written into the queue.
#LOS_ERRNO_QUEUE_INVALIDThe queue handle passed in during queue writing is invalid.
#LOS_ERRNO_QUEUE_WRITE_PTR_NULLThe pointer passed in during queue writing is null.
#LOS_ERRNO_QUEUE_WRITESIZE_ISZEROThe buffer size passed in during queue writing is 0.
#LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPTThe queue cannot be written during an interrupt when the time for waiting to processing the queue expires.
#LOS_ERRNO_QUEUE_NOT_CREATEThe queue into which the data is written is not created.
#LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIGThe buffer size passed in during queue writing is bigger than the queue size.
#LOS_ERRNO_QUEUE_ISFULLNo free node is available during queue writing.
#LOS_ERRNO_QUEUE_PEND_IN_LOCKThe task is forbidden to be blocked on a queue when the task is locked.
#LOS_ERRNO_QUEUE_TIMEOUTThe time set for waiting to processing the queue expires.
Dependency:
  • los_queue.h: The header file that contains the API declaration.
参见
LOS_QueueWrite | LOS_QueueWriteHead

Write data into a queue header.

在文件 los_queue.c394 行定义.

398{
399 UINT32 ret;
400 UINT32 operateType;
401
402 ret = OsQueueWriteParameterCheck(queueID, bufferAddr, &bufferSize, timeout);//参数检查
403 if (ret != LOS_OK) {
404 return ret;
405 }
406
407 operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD);//从头开始写
408 return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeout);//执行写操作
409}
函数调用图:
这是这个函数的调用关系图:

◆ OsQueueMailAlloc()

VOID * OsQueueMailAlloc ( UINT32  queueID,
VOID *  mailPool,
UINT32  timeout 
)

Alloc a stationary memory for a mail.

Description:
This API is used to alloc a stationary memory for a mail according to queueID.
注意
  • Do not alloc memory in unblocking modes such as interrupt.
  • This API cannot be called before the Huawei LiteOS is initialized.
  • The argument timeout is a relative time.
参数
queueID[IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
mailPool[IN] The memory poll that stores the mail.
timeout[IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER].
返回值
#NULLThe memory allocation is failed.
#pMemThe address of alloc memory.
Dependency:
参见
OsQueueMailFree

◆ OsQueueMailFree()

UINT32 OsQueueMailFree ( UINT32  queueID,
VOID *  mailPool,
VOID *  mailMem 
)

Free a stationary memory of a mail.

Description:
This API is used to free a stationary memory for a mail according to queueID.
注意
  • This API cannot be called before the Huawei LiteOS is initialized.
参数
queueID[IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
mailPool[IN] The mail memory poll address.
mailMem[IN] The mail memory block address.
返回值
#LOS_OK0x00000000: The memory free successfully.
#OS_ERRNO_QUEUE_MAIL_HANDLE_INVALID0x02000619: The handle of the queue passed-in when the memory for the queue is being freed is invalid.
#OS_ERRNO_QUEUE_MAIL_PTR_INVALID0x0200061a: The pointer to the memory to be freed is null.
#OS_ERRNO_QUEUE_MAIL_FREE_ERROR0x0200061b: The memory for the queue fails to be freed.
Dependency:
参见
OsQueueMailAlloc

变量说明

◆ g_allQueue

LosQueueCB* g_allQueue
extern

消息队列池

Queue information control block

在文件 los_queue.c98 行定义.