当前位置:网站首页>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

边栏推荐
猜你喜欢

C语言学习-19-全排列

Halcon basic summary (I) cutting pictures and rotating images

GBASE南大通用亮相第六届世界智能大会

Practice of curve replacing CEPH in Netease cloud music

Expand Disk C (allocate the memory of disk d to Disk C)

Fleet | "backstage exploration" issue 3: status management

扩充C盘(将D盘的内存分给C盘)

实验6 8255并行接口实验【微机原理】【实验】

go-zero 微服务实战系列(七、请求量这么高该如何优化)

Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
随机推荐
Solution to JSON parsing problem using curl for Tron API signature broadcast and json Problem record of the loads method
GCC efficient graph revolution for joint node representationlearning and clustering
R language ggplot2 visualization: use the patchwork package to horizontally form two ggplot2 visualization results into a new result visualization combination diagram (using the | symbol)
分布式 CAP 定理的前世今生
Do not use short circuit logic to write STL sorter multi condition comparison
The hidden crisis of Weilai: past, present and future
MIPS汇编语言学习-03-循环
机器学习之深度学习卷积神经网络,实现基于CNN网络的手写字体识别
教育行业SaaS应用管理平台解决方案:助力企业实现经营、管理一体化
Li Kou today's question -522 Longest special sequence
Spark SQL generate JSON
Experiment 6 8255 parallel interface experiment [microcomputer principle] [experiment]
一文教你快速生成MySQL数据库关系图
数组中的第K大元素[堆排 + 建堆的实际时间复杂度]
What! 一条命令搞定监控?
最长连续序列
MIPS assembly language learning-01-sum of two numbers, environment configuration and how to run
R language ggplot2 visualization: use the patchwork package (directly use the plus sign +) to horizontally combine a ggplot2 visualization result and a data table to form a final result graph
Smart supplier management system for chemical manufacturing industry deeply explores the field of supplier management and improves supply chain collaboration
兼顾企业抗疫和发展的5个解决方案,来自IBM