1 /*
2 * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3 *
4 * UniProton is licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 * http://license.coscl.org.cn/MulanPSL2
8 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11 * See the Mulan PSL v2 for more details.
12 * Create: 2009-12-22
13 * Description: 队列维测函数实现
14 */
15 #include "prt_queue_external.h"
16
OsQueueGetParaCheck(U32 innerId,const U32 * num,struct TagQueCb ** queueCb)17 OS_SEC_L2_TEXT U32 OsQueueGetParaCheck(U32 innerId, const U32 *num, struct TagQueCb **queueCb)
18 {
19 if (innerId >= g_maxQueue) {
20 return OS_ERRNO_QUEUE_INVALID;
21 }
22
23 if (num == NULL) {
24 return OS_ERRNO_QUEUE_PTR_NULL;
25 }
26
27 *queueCb = (struct TagQueCb *)GET_QUEUE_HANDLE(innerId);
28 if ((*queueCb)->queueState == OS_QUEUE_UNUSED) {
29 return OS_ERRNO_QUEUE_NOT_CREATE;
30 }
31 return OS_OK;
32 }
33
34 /*
35 * 描述:获取消息队列的历史最大使用长度。
36 */
PRT_QueueGetUsedPeak(U32 queueId,U32 * queueUsedNum)37 OS_SEC_L2_TEXT U32 PRT_QueueGetUsedPeak(U32 queueId, U32 *queueUsedNum)
38 {
39 U32 innerId = OS_QUEUE_INNER_ID(queueId);
40 struct TagQueCb *queueCb = NULL;
41 uintptr_t intSave;
42 U32 ret;
43
44 intSave = OsIntLock();
45 ret = OsQueueGetParaCheck(innerId, queueUsedNum, &queueCb);
46 if (ret != OS_OK) {
47 OsIntRestore(intSave);
48 return ret;
49 }
50
51 *queueUsedNum = (U32)queueCb->nodePeak;
52 OsIntRestore(intSave);
53
54 return OS_OK;
55 }
56
57 /*
58 * 描述:获取当前等待消息队列中指定源任务的待处理消息个数。
59 */
PRT_QueueGetNodeNum(U32 queueId,U32 taskPid,U32 * queueNum)60 OS_SEC_L2_TEXT U32 PRT_QueueGetNodeNum(U32 queueId, U32 taskPid, U32 *queueNum)
61 {
62 U32 ret;
63 U32 loop;
64 uintptr_t intSave;
65 U32 num = 0;
66 U32 numAll = 0;
67 U32 innerId = OS_QUEUE_INNER_ID(queueId);
68 struct TagQueCb *queueCb = NULL;
69 struct QueNode *queueNode = NULL;
70
71 intSave = OsIntLock();
72 ret = OsQueueGetParaCheck(innerId, queueNum, &queueCb);
73 if (ret != OS_OK) {
74 OsIntRestore(intSave);
75 return ret;
76 }
77
78 if (taskPid != OS_QUEUE_PID_INVALID) {
79 for (loop = 0; loop < queueCb->nodeNum; loop++) {
80 queueNode = (struct QueNode *)(uintptr_t)&queueCb->queue[loop * (queueCb->nodeSize)];
81 if (queueNode->srcPid == taskPid) {
82 num++;
83 }
84
85 if (queueNode->srcPid != OS_QUEUE_PID_INVALID) {
86 numAll++;
87 }
88 }
89 }
90
91 *queueNum = (taskPid == OS_QUEUE_PID_ALL) ? numAll : num;
92
93 OsIntRestore(intSave);
94
95 return OS_OK;
96 }
97