更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
vid.c 文件参考

浏览源代码.

函数

UINT32 VidMapListInit (LosProcessCB *processCB)
 
void VidMapDestroy (LosProcessCB *processCB)
 销毁虚拟ID映射 更多...
 
static TimerIdMapNodeFindListNodeByVid (UINT16 vid)
 
static TimerIdMapNodeFindListNodeByRid (UINT32 rid)
 
static UINT16 GetFreeVid (VOID)
 
static VOID ReleaseVid (UINT16 vid)
 
UINT16 AddNodeByRid (UINT16 rid)
 
UINT16 GetRidByVid (UINT16 vid)
 
void RemoveNodeByVid (UINT16 vid)
 

函数说明

◆ AddNodeByRid()

UINT16 AddNodeByRid ( UINT16  rid)

在文件 vid.c178 行定义.

179{
180 TimerIdMapNode *tmp = NULL;
181 LosProcessCB *processCB = OsCurrProcessGet();
182 UINT16 vid;
183
184 tmp = FindListNodeByRid(rid);
185 if (tmp) {
186 return tmp->vid;
187 }
188
189 LOS_MuxLock(&processCB->timerIdMap.vidMapLock, LOS_WAIT_FOREVER);
190 vid = GetFreeVid();
191 if (vid == MAX_INVALID_TIMER_VID) {
193 errno = ENOMEM;
194 return MAX_INVALID_TIMER_VID;
195 }
197 if (tmp == NULL) {
198 PRINT_ERR("%s %d, alloc memory failed\n", __FUNCTION__, __LINE__);
200 errno = ENOMEM;
201 return MAX_INVALID_TIMER_VID;
202 }
203 tmp->rid = rid;
204 tmp->vid = vid;
205
206 LOS_ListTailInsert(&processCB->timerIdMap.head, &tmp->node);
208
209 return vid;
210}
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
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
Definition: los_memory.c:107
LITE_OS_SEC_TEXT UINT32 LOS_MuxUnlock(LosMux *mutex)
释放锁
Definition: los_mux.c:559
LITE_OS_SEC_TEXT UINT32 LOS_MuxLock(LosMux *mutex, UINT32 timeout)
拿互斥锁,
Definition: los_mux.c:437
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
unsigned short UINT16
Definition: los_typedef.h:56
TimerIdMap timerIdMap
LOS_DL_LIST head
Definition: vid_type.h:38
LosMux vidMapLock
Definition: vid_type.h:37
UINT16 rid
Definition: vid_type.h:45
LOS_DL_LIST node
Definition: vid_type.h:44
UINT16 vid
Definition: vid_type.h:46
static TimerIdMapNode * FindListNodeByRid(UINT32 rid)
Definition: vid.c:90
static UINT16 GetFreeVid(VOID)
Definition: vid.c:107
函数调用图:
这是这个函数的调用关系图:

◆ FindListNodeByRid()

static TimerIdMapNode * FindListNodeByRid ( UINT32  rid)
static

在文件 vid.c90 行定义.

91{
92 TimerIdMapNode *idNode = NULL;
93 LosProcessCB *processCB = OsCurrProcessGet();
94
95 LOS_MuxLock(&processCB->timerIdMap.vidMapLock, LOS_WAIT_FOREVER);
96 LOS_DL_LIST_FOR_EACH_ENTRY(idNode, &processCB->timerIdMap.head, TimerIdMapNode, node) {
97 if (rid == idNode->rid) {
99 return idNode;
100 }
101 }
103
104 return NULL;
105}
函数调用图:
这是这个函数的调用关系图:

◆ FindListNodeByVid()

static TimerIdMapNode * FindListNodeByVid ( UINT16  vid)
static

在文件 vid.c73 行定义.

74{
75 TimerIdMapNode *idNode = NULL;
76 LosProcessCB *processCB = OsCurrProcessGet();
77
78 LOS_MuxLock(&processCB->timerIdMap.vidMapLock, LOS_WAIT_FOREVER);
79 LOS_DL_LIST_FOR_EACH_ENTRY(idNode, &processCB->timerIdMap.head, TimerIdMapNode, node) {
80 if (vid == idNode->vid) {
82 return idNode;
83 }
84 }
86
87 return NULL;
88}
函数调用图:
这是这个函数的调用关系图:

◆ GetFreeVid()

static UINT16 GetFreeVid ( VOID  )
static

在文件 vid.c107 行定义.

108{
109 UINT16 i, j;
110 UINT32 num;
111 UINT32 *tmp = NULL;
112 LosProcessCB *processCB = OsCurrProcessGet();
113 TimerIdMap *idMap = &processCB->timerIdMap;
114 UINT16 mapMaxNum = idMap->mapCount;
115
116 for (i = 0; i < mapMaxNum; i++) {
117 num = idMap->bitMap[i];
118 for (j = 0; j < INT_BIT_COUNT; j++) {
119 if ((num & (1 << j)) == 0) {
120 num |= 1 << j;
121 idMap->bitMap[i] = num;
122 return (INT_BIT_COUNT * i + j);
123 }
124 }
125 }
126
127 /* expand bit map */
128 mapMaxNum++;
129 if (mapMaxNum > VID_MAP_MAX_NUM) {
130 PRINT_ERR("%s %d, timer vid run out\n", __FUNCTION__, __LINE__);
131 return MAX_INVALID_TIMER_VID;
132 }
133
134 tmp = (UINT32*)LOS_MemAlloc(m_aucSysMem0, mapMaxNum * sizeof(UINT32));
135 if (tmp == NULL) {
136 PRINT_ERR("%s %d, alloc memory failed\n", __FUNCTION__, __LINE__);
137 return MAX_INVALID_TIMER_VID;
138 }
139
140 (void)memcpy_s(tmp, mapMaxNum * sizeof(UINT32), idMap->bitMap, (mapMaxNum - 1) * sizeof(UINT32));
142 idMap->bitMap = tmp;
143 idMap->mapCount = mapMaxNum;
144 idMap->bitMap[i] = 1;
145 return (INT_BIT_COUNT * i);
146}
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
unsigned int UINT32
Definition: los_typedef.h:57
UINT16 mapCount
Definition: vid_type.h:39
UINT32 * bitMap
Definition: vid_type.h:40
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图:
这是这个函数的调用关系图:

◆ GetRidByVid()

UINT16 GetRidByVid ( UINT16  vid)

在文件 vid.c212 行定义.

213{
215 if (tmp) {
216 return tmp->rid;
217 }
218 return 0xffff;
219}
static TimerIdMapNode * FindListNodeByVid(UINT16 vid)
Definition: vid.c:73
函数调用图:
这是这个函数的调用关系图:

◆ ReleaseVid()

static VOID ReleaseVid ( UINT16  vid)
static

在文件 vid.c148 行定义.

149{
150 UINT16 a, b;
151 UINT32 *tmpMap = NULL;
152 LosProcessCB *processCB = OsCurrProcessGet();
153 TimerIdMap *idMap = &processCB->timerIdMap;
154 UINT16 mapMaxNum = idMap->mapCount;
155
156 if (vid >= (VID_MAP_MAX_NUM * INT_BIT_COUNT)) {
157 return;
158 }
159
160 a = vid >> INT_BIT_SHIFT;
161 b = vid & (INT_BIT_COUNT - 1);
162
163 idMap->bitMap[a] &= ~(1 << b);
164
165 /* shrink bit map */
166 if (mapMaxNum > 1) {
167 if (idMap->bitMap[mapMaxNum - 1] == 0) {
168 mapMaxNum--;
169 tmpMap = LOS_MemRealloc(m_aucSysMem0, idMap->bitMap, mapMaxNum * sizeof(UINT32));
170 if (tmpMap) {
171 idMap->bitMap = tmpMap;
172 idMap->mapCount = mapMaxNum;
173 }
174 }
175 }
176}
VOID * LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size)
按size大小重新分配内存块,并将原内存块内容拷贝到新内存块。如果新内存块申请成功,则释放原内存块
Definition: los_memory.c:1510
函数调用图:
这是这个函数的调用关系图:

◆ RemoveNodeByVid()

void RemoveNodeByVid ( UINT16  vid)

在文件 vid.c221 行定义.

222{
223 TimerIdMapNode *tmp = NULL;
224 LosProcessCB *processCB = OsCurrProcessGet();
225
226 tmp = FindListNodeByVid(vid);
227 if (tmp == NULL) {
228 return;
229 }
230
231 LOS_MuxLock(&processCB->timerIdMap.vidMapLock, LOS_WAIT_FOREVER);
232 LOS_ListDelete(&tmp->node);
233 ReleaseVid(tmp->vid);
236
237 return;
238}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
static VOID ReleaseVid(UINT16 vid)
Definition: vid.c:148
函数调用图:
这是这个函数的调用关系图:

◆ VidMapDestroy()

void VidMapDestroy ( LosProcessCB processCB)

销毁虚拟ID映射

在文件 vid.c57 行定义.

58{
59 TimerIdMapNode *idNode = NULL;
60 TimerIdMapNode *idNodeNext = NULL;
61
62 LOS_MuxLock(&processCB->timerIdMap.vidMapLock, LOS_WAIT_FOREVER);
63 LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(idNode, idNodeNext, &processCB->timerIdMap.head, TimerIdMapNode, node) {
64 LOS_ListDelete(&idNode->node);
66 }
67
71}
LITE_OS_SEC_TEXT UINT32 LOS_MuxDestroy(LosMux *mutex)
销毁互斥锁
Definition: los_mux.c:289
函数调用图:
这是这个函数的调用关系图:

◆ VidMapListInit()

UINT32 VidMapListInit ( LosProcessCB processCB)

在文件 vid.c36 行定义.

37{
38 (void)memset_s(&processCB->timerIdMap, sizeof(TimerIdMap), 0, sizeof(TimerIdMap));
39 LOS_ListInit(&processCB->timerIdMap.head);
40 processCB->timerIdMap.bitMap = (UINT32*)LOS_MemAlloc(m_aucSysMem0, sizeof(UINT32));
41 if (processCB->timerIdMap.bitMap == NULL) {
42 PRINT_ERR("%s %d, alloc memory failed\n", __FUNCTION__, __LINE__);
43 return LOS_NOK;
44 }
45
46 processCB->timerIdMap.mapCount = 1;
47 (void)memset_s(processCB->timerIdMap.bitMap, sizeof(UINT32), 0, sizeof(UINT32));
48 if (LOS_MuxInit(&processCB->timerIdMap.vidMapLock, NULL) != LOS_OK) {
49 PRINT_ERR("%s %d, Create mutex for vmm failed\n", __FUNCTION__, __LINE__);
51 processCB->timerIdMap.bitMap = NULL;
52 return LOS_NOK;
53 }
54 return LOS_OK;
55}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
LITE_OS_SEC_TEXT UINT32 LOS_MuxInit(LosMux *mutex, const LosMuxAttr *attr)
初始化互斥锁
Definition: los_mux.c:262
函数调用图:
这是这个函数的调用关系图: