当前位置:网站首页>Openharmony - detailed source code of Kernel Object Events
Openharmony - detailed source code of Kernel Object Events
2022-06-28 15:37:00 【InfoQ】
Key data structure
typedef struct tagEvent {
UINT32 uwEventID;
LOS_DL_LIST stEventList; /**< Event control block linked list */
} EVENT_CB_S, *PEVENT_CB_S;
Event initialization
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
{
if (eventCB == NULL) {
return LOS_ERRNO_EVENT_PTR_NULL;
}
eventCB->uwEventID = 0;
LOS_ListInit(&eventCB->stEventList);
OsHookCall(LOS_HOOK_TYPE_EVENT_INIT, eventCB);
return LOS_OK;
}

Event write operation
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
{
...
eventCB->uwEventID |= events; ---1
if (!LOS_ListEmpty(&eventCB->stEventList)) { ---2
for (resumedTask = LOS_DL_LIST_ENTRY((&eventCB->stEventList)->pstNext, LosTaskCB, pendList);
&resumedTask->pendList != (&eventCB->stEventList);) { -------3
nextTask = LOS_DL_LIST_ENTRY(resumedTask->pendList.pstNext, LosTaskCB, pendList);
if (((resumedTask->eventMode & LOS_WAITMODE_OR) && (resumedTask->eventMask & events) != 0) ||
((resumedTask->eventMode & LOS_WAITMODE_AND) &&
((resumedTask->eventMask & eventCB->uwEventID) == resumedTask->eventMask))) {
exitFlag = 1;
OsSchedTaskWake(resumedTask); ---4
}
resumedTask = nextTask;
}
if (exitFlag == 1) {
LOS_IntRestore(intSave);
LOS_Schedule(); ---5
return LOS_OK;
}
}
...
}

Event read operation
LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventID, UINT32 eventMask, UINT32 mode)
{
UINT32 ret = 0;
UINT32 intSave;
if (eventID == NULL) {
return LOS_ERRNO_EVENT_PTR_NULL;
}
intSave = LOS_IntLock();
if (mode & LOS_WAITMODE_OR) {
if ((*eventID & eventMask) != 0) { ---1
ret = *eventID & eventMask;
}
} else {
if ((eventMask != 0) && (eventMask == (*eventID & eventMask))) { ---2
ret = *eventID & eventMask;
}
}
if (ret && (mode & LOS_WAITMODE_CLR)) { ---3
*eventID = *eventID & ~(ret);
}
LOS_IntRestore(intSave);
return ret;
}
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeOut)
{
...
ret = LOS_EventPoll(&(eventCB->uwEventID), eventMask, mode); ---1
OsHookCall(LOS_HOOK_TYPE_EVENT_READ, eventCB, eventMask, mode, timeOut);
if (ret == 0) {
if (timeOut == 0) {
LOS_IntRestore(intSave);
return ret;
}
if (g_losTaskLock) {
LOS_IntRestore(intSave);
return LOS_ERRNO_EVENT_READ_IN_LOCK;
}
runTsk = g_losTask.runTask;
runTsk->eventMask = eventMask;
runTsk->eventMode = mode;
OsSchedTaskWait(&eventCB->stEventList, timeOut); ---2
LOS_IntRestore(intSave);
LOS_Schedule(); ---3
intSave = LOS_IntLock();
if (runTsk->taskStatus & OS_TASK_STATUS_TIMEOUT) {
runTsk->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
LOS_IntRestore(intSave);
return LOS_ERRNO_EVENT_READ_TIMEOUT;
}
ret = LOS_EventPoll(&eventCB->uwEventID, eventMask, mode); ---4
}
...
}

Event destroy
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMask)
{
...
eventCB->uwEventID &= eventMask;
...
}
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
{
...
eventCB->stEventList.pstNext = (LOS_DL_LIST *)NULL;
eventCB->stEventList.pstPrev = (LOS_DL_LIST *)NULL;
...
}
Summary

边栏推荐
- Classic model transformer
- C语言学习-19-全排列
- Longest continuous sequence
- In depth learning foundation summary
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一段文本内容横向组合起来形成最终结果图
- The k-th element in the array [heap row + actual time complexity of heap building]
- Solution to JSON parsing problem using curl for Tron API signature broadcast and json Problem record of the loads method
- Experiment 6 8255 parallel interface experiment [microcomputer principle] [experiment]
- 最长连续序列
- Basic grammar of C language
猜你喜欢
石油化工行业供应链系统驱动管理模式创新升级,强化企业内部管理
Fleet |「後臺探秘」第 3 期:狀態管理
MIPS assembly language learning-03-cycle
S2b2c system website solution for kitchen and bathroom electrical appliance industry: create s2b2c platform Omni channel commercial system
信创操作系统--麒麟Kylin桌面操作系统 (项目十 安全中心)
Jenkins的安装及使用
Expand Disk C (allocate the memory of disk d to Disk C)
Leetcode 48. Rotate image (yes, resolved)
实验6 8255并行接口实验【微机原理】【实验】
High "green premium" of environmental protection products? How far is the low-carbon lifestyle from people
随机推荐
完整的模型训练套路(一)
Flutter dart语言特点总结
信创操作系统--麒麟Kylin桌面操作系统 (项目十 安全中心)
[C language] how to implement plural types
实验6 8255并行接口实验【微机原理】【实验】
With a return of 5000 times, the South African newspaper invested in Tencent to make a province
雷科防务:4D毫米波雷达产品预计可以在年底量产供货
深度学习基础汇总
GCC efficient graph revolution for joint node representationlearning and clustering
C语言学习-19-全排列
Validate palindrome string
Leetcode 705. Design hash collection
C#/VB.NET 将PDF转为Excel
Classic model transformer
机器学习之深度学习卷积神经网络,实现基于CNN网络的手写字体识别
After QQ was stolen, a large number of users "died"
Not being a meta universe now is like not buying a house 20 years ago!
浪擎与浪潮,一个从OEM到价值共生的生态样板
Smart supplier management system for chemical manufacturing industry deeply explores the field of supplier management and improves supply chain collaboration
R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图、将两个可视的组合结果对齐