• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
3  * Description: Priority Queue Private HeadFile
4  * Author: Huawei LiteOS Team
5  * Create: 2013-01-01
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted provided that the following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without specific prior written
15  * permission.
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * --------------------------------------------------------------------------- */
28 
29 #ifndef _LOS_PRIQUEUE_PRI_H
30 #define _LOS_PRIQUEUE_PRI_H
31 
32 #include "los_list.h"
33 #include "los_typedef.h"
34 #include "los_spinlock.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
40 typedef enum {
41     PRI_QUEUE_HEAD = 0,
42     PRI_QUEUE_TAIL = 1
43 } PriQueueHeadTail;
44 
45 /* Number of priority queues. Now LiteOS only supports 32 priorities. */
46 #define OS_PRIORITY_QUEUE_NUM 32
47 #define PRIQUEUE_PRIOR0_BIT   0x80000000U
48 
49 /* This API is used to initialize the priority queue. */
50 extern VOID OsPriQueueInit(VOID);
51 
52 /* This API is used to delete a item from the priority queue. */
53 extern VOID OsPriQueueDequeue(LOS_DL_LIST *priqueueItem);
54 
55 /*
56  * These two functions are protect version of OsPriQueueEnqueue and OsPriQueueDequeue.
57  * In SCHED_SQ, the task status and priqueue are protected by the global schedule lock, this two function
58  * are just the same as the previous ones.
59  */
60 #ifdef LOSCFG_SCHED_MQ
61 
62 struct tagTaskCB;
63 
64 typedef struct {
65     UINT32              bitmap;                         /* priority-queue bitmap */
66     LOS_DL_LIST         queues[OS_PRIORITY_QUEUE_NUM];  /* one for each priority */
67     INT32               readyTasks;                     /* number of ready tasks */
68     SPIN_LOCK_S         lock;                           /* private spinlock */
69     struct tagTaskCB    *prevTask;                      /* previously ran task */
70 } PriQueue;
71 
72 /* Per-cpu priority queue */
73 extern PriQueue g_priQueue[LOSCFG_KERNEL_CORE_NUM];
74 
75 /*
76  * This API is used to get whether the priority queue is empty.
77  */
OsPriQueueIsEmpty(UINT32 priority)78 STATIC INLINE BOOL OsPriQueueIsEmpty(UINT32 priority)
79 {
80     PriQueue *priQueue = &g_priQueue[ArchCurrCpuid()];
81 
82     return ((priQueue->bitmap & (PRIQUEUE_PRIOR0_BIT >> priority)) == 0);
83 }
84 
85 extern VOID OsPriQueueSimpleEnqueue(LOS_DL_LIST *queueNode, PriQueueHeadTail mode);
86 extern VOID OsPriQueueEnqueueProtect(LOS_DL_LIST *queueNode, UINT32 priority, PriQueueHeadTail mode);
87 extern BOOL OsPriQueueDequeueProtect(LOS_DL_LIST *priqueueItem);
88 
89 #else /* LOSCFG_SCHED_SQ */
90 /* This API is used to insert a item to the priority queue according to the priority of this item. */
91 extern VOID OsPriQueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority, PriQueueHeadTail mode);
92 
93 /*
94  * This API is used to get whether the priority queue is empty.
95  */
96 extern BOOL OsPriQueueIsEmpty(UINT32 priority);
97 
OsPriQueueEnqueueProtect(LOS_DL_LIST * queueNode,UINT32 priority,PriQueueHeadTail mode)98 STATIC INLINE VOID OsPriQueueEnqueueProtect(LOS_DL_LIST *queueNode, UINT32 priority, PriQueueHeadTail mode)
99 {
100     OsPriQueueEnqueue(queueNode, priority, mode);
101 }
102 
OsPriQueueDequeueProtect(LOS_DL_LIST * priqueueItem)103 STATIC INLINE BOOL OsPriQueueDequeueProtect(LOS_DL_LIST *priqueueItem)
104 {
105     OsPriQueueDequeue(priqueueItem);
106     return TRUE;
107 }
108 #endif /* LOSCFG_SCHED_MQ */
109 
110 /*
111  * This API is used to obtain the item with highest priority in the priority queue.
112  */
113 extern LOS_DL_LIST *OsPriQueueTop(VOID);
114 
115 #ifdef __cplusplus
116 }
117 #endif /* __cplusplus */
118 
119 #endif /* _LOS_PRIQUEUE_PRI_H */
120