• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_mem.h"
16 #include "prt_queue_external.h"
17 
18 /*
19  * 描述:删除队列,只提给供实验室使用
20  */
PRT_QueueDelete(U32 queueId)21 OS_SEC_L4_TEXT U32 PRT_QueueDelete(U32 queueId)
22 {
23     uintptr_t intSave;
24     U32 ret;
25     U32 innerId = OS_QUEUE_INNER_ID(queueId);
26     struct TagQueCb *queueCb = NULL;
27 
28     if (innerId >= g_maxQueue) {
29         return OS_ERRNO_QUEUE_INVALID;
30     }
31 
32     /* 获取指定队列控制块 */
33     queueCb = (struct TagQueCb *)GET_QUEUE_HANDLE(innerId);
34     intSave = OsIntLock();
35     if (queueCb->queueState == OS_QUEUE_UNUSED) {
36         ret = OS_ERRNO_QUEUE_NOT_CREATE;
37         goto QUEUE_END;
38     }
39 
40     if (!ListEmpty(&queueCb->writeList) || !ListEmpty(&queueCb->readList)) {
41         ret = OS_ERRNO_QUEUE_IN_TSKUSE;
42         goto QUEUE_END;
43     }
44 
45     if ((queueCb->writableCnt + queueCb->readableCnt) != queueCb->nodeNum) {
46         ret = OS_ERRNO_QUEUE_BUSY;
47         goto QUEUE_END;
48     }
49 
50     ret = PRT_MemFree((U32)OS_MID_QUEUE, (void *)(queueCb->queue));
51     if (ret != OS_OK) {
52         goto QUEUE_END;
53     }
54 
55     queueCb->queueState = OS_QUEUE_UNUSED;
56 
57 QUEUE_END:
58     OsIntRestore(intSave);
59     return ret;
60 }
61