From 704cca97b17972d1640fd33b1fa0b5917bb92b19 Mon Sep 17 00:00:00 2001 From: kenneth Date: Thu, 22 Jul 2021 12:03:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DQUEUE=5FINFO=5FS?= =?UTF-8?q?=E4=B8=ADwaitReadTask=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=A4=A7=E4=BA=8E32=E7=9A=84=E4=BB=BB=E5=8A=A1=E7=BC=96?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据任务最大数创建waitReadTask数组来保存任务编号信息 close #I41N78 Signed-off-by: kenneth --- kernel/include/los_queue.h | 19 ++++++++++++++++--- kernel/src/los_queue.c | 6 +++--- .../sample/kernel/queue/LLt_los_queue_003.c | 2 +- .../sample/kernel/queue/Llt_los_queue_001.c | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/kernel/include/los_queue.h b/kernel/include/los_queue.h index c3aebc0d..797463bd 100644 --- a/kernel/include/los_queue.h +++ b/kernel/include/los_queue.h @@ -38,6 +38,7 @@ #define _LOS_QUEUE_H #include "los_list.h" +#include "los_config.h" #ifdef __cplusplus #if __cplusplus @@ -330,6 +331,18 @@ extern "C" { */ #define LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1f) +/** + * @ingroup los_queue + * In struct QUEUE_INFO_S, the length of each waitReadTask/waitWriteTask/waitMemTask array depends on the value + * LOSCFG_BASE_CORE_TSK_LIMIT. The type of each array element is UINT32, which means that each element could mark 32(=2^5) tasks. + * OS_WAIT_TASK_ARRAY_LEN is used to calculate the array length. + * OS_WAIT_TASK_ID_TO_ARRAY_IDX is used to transfer task ID to array index. + * OS_WAIT_TASK_ARRAY_ELEMENT_MASK is the mask for each element. + */ +#define OS_WAIT_TASK_ARRAY_LEN ((LOSCFG_BASE_CORE_TSK_LIMIT >> 5) + 1) +#define OS_WAIT_TASK_ID_TO_ARRAY_IDX(taskID) (taskID >> 5) +#define OS_WAIT_TASK_ARRAY_ELEMENT_MASK ((1 << OS_WAIT_TASK_ARRAY_LEN) - 1) + /** * @ingroup los_queue * Structure of the block for queue information query @@ -342,9 +355,9 @@ typedef struct tagQueueInfo { UINT16 queueTail; /**< Node tail */ UINT16 writableCnt; /**< Count of writable resources */ UINT16 readableCnt; /**< Count of readable resources */ - UINT32 waitReadTask; /**< Resource reading task */ - UINT32 waitWriteTask; /**< Resource writing task */ - UINT32 waitMemTask; /**< Memory task */ + UINT32 waitReadTask[OS_WAIT_TASK_ARRAY_LEN]; /**< Resource reading task*/ + UINT32 waitWriteTask[OS_WAIT_TASK_ARRAY_LEN]; /**< Resource writing task */ + UINT32 waitMemTask[OS_WAIT_TASK_ARRAY_LEN]; /**< Memory task */ } QUEUE_INFO_S; /** diff --git a/kernel/src/los_queue.c b/kernel/src/los_queue.c index 863d0a22..9633d4d4 100644 --- a/kernel/src/los_queue.c +++ b/kernel/src/los_queue.c @@ -651,15 +651,15 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *que queueInfo->writableCnt = queueCB->readWriteableCnt[OS_QUEUE_WRITE]; LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_READ], LosTaskCB, pendList) { - queueInfo->waitReadTask |= (1 << tskCB->taskID); + queueInfo->waitReadTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(tskCB->taskID)] |= (1 << (tskCB->taskID & OS_WAIT_TASK_ARRAY_ELEMENT_MASK)); } LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->readWriteList[OS_QUEUE_WRITE], LosTaskCB, pendList) { - queueInfo->waitWriteTask |= (1 << tskCB->taskID); + queueInfo->waitWriteTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(tskCB->taskID)] |= (1 << (tskCB->taskID & OS_WAIT_TASK_ARRAY_ELEMENT_MASK)); } LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &queueCB->memList, LosTaskCB, pendList) { - queueInfo->waitMemTask |= (1 << tskCB->taskID); + queueInfo->waitMemTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(tskCB->taskID)] |= (1 << (tskCB->taskID & OS_WAIT_TASK_ARRAY_ELEMENT_MASK)); } QUEUE_END: diff --git a/testsuits/sample/kernel/queue/LLt_los_queue_003.c b/testsuits/sample/kernel/queue/LLt_los_queue_003.c index 961d2abe..721910d6 100644 --- a/testsuits/sample/kernel/queue/LLt_los_queue_003.c +++ b/testsuits/sample/kernel/queue/LLt_los_queue_003.c @@ -69,7 +69,7 @@ static UINT32 Testcase(VOID) ret = LOS_QueueCreate("Q122", 1, &g_uwQueueID122, 0, QUEUE_BASE_MSGSIZE); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - ret = LOS_MemboxInit((VOID *)g_aucMailBoxPool, sizeof(g_aucMailBoxPool) * 1, sizeof(g_aucMailBoxPool)); + ret = LOS_MemboxInit((VOID *)g_aucMailBoxPool, sizeof(g_aucMailBoxPool) * 2, sizeof(g_aucMailBoxPool)); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); memBox = OsQueueMailAlloc(g_uwQueueID122, (VOID *)g_aucMailBoxPool, LOS_NO_WAIT); diff --git a/testsuits/sample/kernel/queue/Llt_los_queue_001.c b/testsuits/sample/kernel/queue/Llt_los_queue_001.c index db75cf40..9353693a 100644 --- a/testsuits/sample/kernel/queue/Llt_los_queue_001.c +++ b/testsuits/sample/kernel/queue/Llt_los_queue_001.c @@ -55,14 +55,14 @@ static UINT32 Testcase(VOID) ret = LOS_QueueInfoGet(g_testQueueID01, &queueInfo); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT2); - ICUNIT_GOTO_EQUAL(queueInfo.waitReadTask, (1 << g_testTaskID01), queueInfo.waitReadTask, EXIT2); + ICUNIT_GOTO_EQUAL(queueInfo.waitReadTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(g_testTaskID01)], 1 << (g_testTaskID01 & OS_WAIT_TASK_ARRAY_ELEMENT_MASK), queueInfo.waitReadTask, EXIT2); ret = LOS_QueueWrite(g_testQueueID01, &buff1, QUEUE_BASE_MSGSIZE, 0); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT2); ret = LOS_QueueInfoGet(g_testQueueID01, &queueInfo); ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT2); - ICUNIT_GOTO_EQUAL(queueInfo.waitWriteTask, (1 << g_testTaskID01), queueInfo.waitWriteTask, EXIT2); + ICUNIT_GOTO_EQUAL(queueInfo.waitWriteTask[OS_WAIT_TASK_ID_TO_ARRAY_IDX(g_testTaskID01)], 1 << (g_testTaskID01 & OS_WAIT_TASK_ARRAY_ELEMENT_MASK), queueInfo.waitWriteTask, EXIT2); EXIT2: ret = LOS_TaskDelete(g_testTaskID01); -- GitLab