94#ifdef LOSCFG_BASE_IPC_MUX
95#define MUTEXATTR_TYPE_MASK 0x0FU
122 if ((attr == NULL) || (outType == NULL)) {
126 type = (
INT32)(attr->
type & MUTEXATTR_TYPE_MASK);
148 if ((attr != NULL) && (protocol != NULL)) {
180 if (prioceiling != NULL) {
189 if ((attr == NULL) ||
190 (prioceiling < OS_TASK_PRIORITY_HIGHEST) ||
191 (prioceiling > OS_TASK_PRIORITY_LOWEST)) {
204 if ((mutex == NULL) ||
205 (prioceiling < OS_TASK_PRIORITY_HIGHEST) ||
206 (prioceiling > OS_TASK_PRIORITY_LOWEST)) {
211 if (retLock != LOS_OK) {
215 if (oldPrioceiling != NULL) {
222 if ((ret == LOS_OK) && (retLock != LOS_OK)) {
231 if ((mutex != NULL) && (prioceiling != NULL) && (mutex->
magic == OS_MUX_MAGIC)) {
241 if ((mutex != NULL) && (mutex->
magic == OS_MUX_MAGIC)) {
280 SCHEDULER_LOCK(intSave);
284 mutex->
magic = OS_MUX_MAGIC;
285 SCHEDULER_UNLOCK(intSave);
297 SCHEDULER_LOCK(intSave);
298 if (mutex->
magic != OS_MUX_MAGIC) {
299 SCHEDULER_UNLOCK(intSave);
304 SCHEDULER_UNLOCK(intSave);
308 (VOID)memset_s(mutex,
sizeof(
LosMux), 0,
sizeof(
LosMux));
309 SCHEDULER_UNLOCK(intSave);
354 mutex->
owner = (VOID *)runTask;
380 runTask->
taskMux = (VOID *)mutex;
388 ret = runTask->
ops->
wait(runTask, node, timeout);
389 if (ret == LOS_ERRNO_TSK_TIMEOUT) {
402 if (mutex->
magic != OS_MUX_MAGIC) {
421 if (mutex->
magic != OS_MUX_MAGIC) {
429 if ((mutex->
owner != NULL) &&
453 if (runTask->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
454 PRINTK(
"Warning: DO NOT call %s in system tasks.\n", __FUNCTION__);
458 SCHEDULER_LOCK(intSave);
460 SCHEDULER_UNLOCK(intSave);
480 if (runTask->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
481 PRINTK(
"Warning: DO NOT call %s in system tasks.\n", __FUNCTION__);
485 SCHEDULER_LOCK(intSave);
487 SCHEDULER_UNLOCK(intSave);
510 LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(mutex->
muxList)));
514 mutex->
owner = (VOID *)resumedTask;
518 resumedTask->
ops->
wake(resumedTask);
520 if (needSched != NULL) {
529 if (mutex->
magic != OS_MUX_MAGIC) {
562 BOOL needSched = FALSE;
576 if (runTask->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
577 PRINTK(
"Warning: DO NOT call %s in system tasks.\n", __FUNCTION__);
581 SCHEDULER_LOCK(intSave);
583 SCHEDULER_UNLOCK(intSave);
584 if (needSched == TRUE) {
VOID OsBackTrace(VOID)
Kernel backtrace function.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
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.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
LITE_OS_SEC_TEXT UINT32 LOS_MuxTrylock(LosMux *mutex)
尝试要锁,没拿到也不等,直接返回,不纠结
LITE_OS_SEC_TEXT UINT32 LOS_MuxInit(LosMux *mutex, const LosMuxAttr *attr)
初始化互斥锁
LITE_OS_SEC_TEXT UINT32 LOS_MuxUnlock(LosMux *mutex)
释放锁
LITE_OS_SEC_TEXT UINT32 LOS_MuxDestroy(LosMux *mutex)
销毁互斥锁
LITE_OS_SEC_TEXT UINT32 LOS_MuxLock(LosMux *mutex, UINT32 timeout)
拿互斥锁,
VOID LOS_Schedule(VOID)
Trigger active task scheduling.
VOID LOS_MpSchedule(UINT32 target)
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrGetProtocol(const LosMuxAttr *attr, INT32 *protocol)
获取互斥锁的类型属性
LITE_OS_SEC_TEXT BOOL LOS_MuxIsValid(const LosMux *mutex)
互斥锁是否有效
STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
最坏情况就是拿锁失败,让出CPU,变成阻塞任务,等别的任务释放锁后排到自己了接着执行.
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrSetType(LosMuxAttr *attr, INT32 type)
设置互斥锁的类型属性
STATIC UINT32 OsMuxPostOp(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
OsMuxPostOp 是否有其他任务持有互斥锁而处于阻塞状,如果是就要唤醒它,注意唤醒一个任务的操作是由别的任务完成的 OsMuxPostOp只由OsMuxUnlockUnsafe,...
VOID OsMuxBitmapRestore(const LosMux *mutex, const LOS_DL_LIST *list, const LosTaskCB *runTask)
恢复互斥锁位图
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrGetPrioceiling(const LosMuxAttr *attr, INT32 *prioceiling)
获取互斥锁属性优先级
UINT32 OsMuxTrylockUnsafe(LosMux *mutex, UINT32 timeout)
尝试加锁,
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrDestroy(LosMuxAttr *attr)
????? 销毁互斥属 ,这里啥也没干呀
LITE_OS_SEC_TEXT UINT32 LOS_MuxSetPrioceiling(LosMux *mutex, INT32 prioceiling, INT32 *oldPrioceiling)
设置互斥锁的优先级的上限,老优先级由oldPrioceiling带走
UINT32 OsMuxLockUnsafe(LosMux *mutex, UINT32 timeout)
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrSetProtocol(LosMuxAttr *attr, INT32 protocol)
设置互斥锁属性的协议
LITE_OS_SEC_TEXT UINT32 LOS_MuxGetPrioceiling(const LosMux *mutex, INT32 *prioceiling)
获取互斥锁的优先级的上限
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrSetPrioceiling(LosMuxAttr *attr, INT32 prioceiling)
设置互斥锁属性的优先级的上限
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrGetType(const LosMuxAttr *attr, INT32 *outType)
获取互斥锁的类型属性,由outType接走,不送!
STATIC UINT32 OsCheckMutexAttr(const LosMuxAttr *attr)
检查互斥锁属性是否OK,否则 no ok :|)
STATIC VOID OsMuxBitmapSet(const LosMux *mutex, const LosTaskCB *runTask)
设置互斥锁位图
UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrInit(LosMuxAttr *attr)
互斥属性初始化
@ LOS_MUX_ERRORCHECK
进行错误检查,如果一个线程企图对一个已经锁住的mutex进行relock或对未加锁的unlock,将返回一个错误。
@ LOS_MUX_RECURSIVE
递归锁 允许同一线程在互斥量解锁前对该互斥量进行多次加锁。递归互斥量维护锁的计数,在解锁次数和加锁次数不相同的情况下,不会释放锁,别的线程就无法加锁此互斥量。
@ LOS_MUX_NORMAL
非递归锁 只有[0.1]两个状态,不做任何特殊的错误检,不进行deadlock detection(死锁检测)
@ LOS_MUX_PRIO_PROTECT
详见: OsMuxPendOp 中的注解,详细说明了LOS_MUX_PRIO_PROTECT的含义
@ LOS_MUX_PRIO_NONE
线程的优先级和调度不会受到互斥锁影响,先来后到,普通排队.
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
LOS_DL_LIST * OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList)
STATIC INLINE BOOL OsPreemptableInSched(VOID)
INT32 OsSchedParamCompare(const LosTaskCB *task1, const LosTaskCB *task2)
STATIC INLINE VOID OsTaskWaitSetPendMask(UINT16 mask, UINTPTR lockID, UINT32 timeout)
设置事件阻塞掩码,即设置任务的等待事件.
STATIC INLINE VOID OsTaskWakeClearPendMask(LosTaskCB *resumeTask)
清除事件阻塞掩码,即任务不再等待任何事件.
struct LOS_DL_LIST * pstPrev
struct LOS_DL_LIST * pstNext
VOID(* priorityInheritance)(LosTaskCB *owner, const SchedParam *param)
UINT32(* wait)(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 timeout)
任务等待
VOID(* wake)(LosTaskCB *taskCB)
任务唤醒
VOID(* priorityRestore)(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param)
恢复调度参数
UINT32(* schedParamGet)(const LosTaskCB *taskCB, SchedParam *param)
获取调度参数