|
|
|
@ -38,16 +38,17 @@
|
|
|
|
|
#if __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
#endif /* __cplusplus */nbb
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
LOS_DL_LIST muxListHead; /* Task-held mutexs list */
|
|
|
|
|
UINT64 lastAccessTime; /* The last operation time */
|
|
|
|
|
LOS_DL_LIST muxListHead; /* Task-held mutexs list */ //用于管理任务持有的互斥锁列表//
|
|
|
|
|
UINT64 lastAccessTime; /* The last operation time */ //记录最后一次操作的时间//
|
|
|
|
|
} MuxDLinkCB;
|
|
|
|
|
|
|
|
|
|
/*管理任务持有的互斥锁列表和跟踪死锁情况*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
LOS_DL_LIST muxList; /* Insert mutex into the owner task CB */
|
|
|
|
|
VOID *muxCB; /* The Mutex CB pointer */
|
|
|
|
|
LOS_DL_LIST muxList; /* Insert mutex into the owner task CB */ //用于将互斥锁插入到所属任务的控制块中//
|
|
|
|
|
VOID *muxCB; /* The Mutex CB pointer */ //指向互斥锁控制块的指针//
|
|
|
|
|
} MuxDLinkNode;
|
|
|
|
|
|
|
|
|
|
STATIC MuxDLinkCB *g_muxDeadlockCBArray = NULL;
|
|
|
|
@ -57,9 +58,9 @@ STATIC MuxDLinkCB *g_muxDeadlockCBArray = NULL;
|
|
|
|
|
* that has not been scheduled within this time.
|
|
|
|
|
* The unit is tick.
|
|
|
|
|
*/
|
|
|
|
|
#define OS_MUX_DEADLOCK_CHECK_THRESHOLD 60000
|
|
|
|
|
#define OS_MUX_DEADLOCK_CHECK_THRESHOLD 60000 //定义两次检查互斥锁死锁之间的最小时间间隔,单位为毫秒//
|
|
|
|
|
|
|
|
|
|
UINT32 OsMuxDlockCheckInit(VOID)
|
|
|
|
|
UINT32 OsMuxDlockCheckInit(VOID) //用于分配内存并初始化互斥锁控制块列表//
|
|
|
|
|
{
|
|
|
|
|
UINT32 index;
|
|
|
|
|
UINT32 size = (LOSCFG_BASE_CORE_TSK_LIMIT + 1) * sizeof(MuxDLinkCB);
|
|
|
|
@ -78,7 +79,7 @@ UINT32 OsMuxDlockCheckInit(VOID)
|
|
|
|
|
return LOS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID OsMuxDlockNodeInsert(UINT32 taskId, VOID *muxCB)
|
|
|
|
|
VOID OsMuxDlockNodeInsert(UINT32 taskId, VOID *muxCB) //用于向指定任务的互斥锁链表中插入一个互斥锁节点//
|
|
|
|
|
{
|
|
|
|
|
MuxDLinkNode *muxDLNode = NULL;
|
|
|
|
|
|
|
|
|
@ -96,7 +97,7 @@ VOID OsMuxDlockNodeInsert(UINT32 taskId, VOID *muxCB)
|
|
|
|
|
LOS_ListTailInsert(&g_muxDeadlockCBArray[taskId].muxListHead, &muxDLNode->muxList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID OsMuxDlockNodeDelete(UINT32 taskId, const VOID *muxCB)
|
|
|
|
|
VOID OsMuxDlockNodeDelete(UINT32 taskId, const VOID *muxCB) //用于从指定任务的互斥锁链表中删除指定的互斥锁节点//
|
|
|
|
|
{
|
|
|
|
|
MuxDLinkCB *muxDLCB = NULL;
|
|
|
|
|
LOS_DL_LIST *list = NULL;
|
|
|
|
@ -117,7 +118,7 @@ VOID OsMuxDlockNodeDelete(UINT32 taskId, const VOID *muxCB)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID OsTaskTimeUpdate(UINT32 taskId, UINT64 tickCount)
|
|
|
|
|
VOID OsTaskTimeUpdate(UINT32 taskId, UINT64 tickCount) //用于更新任务的最后访问时间//
|
|
|
|
|
{
|
|
|
|
|
if (taskId > LOSCFG_BASE_CORE_TSK_LIMIT) {
|
|
|
|
|
return;
|
|
|
|
@ -126,7 +127,7 @@ VOID OsTaskTimeUpdate(UINT32 taskId, UINT64 tickCount)
|
|
|
|
|
g_muxDeadlockCBArray[taskId].lastAccessTime = tickCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC VOID OsDeadlockBackTrace(const LosTaskCB *taskCB)
|
|
|
|
|
STATIC VOID OsDeadlockBackTrace(const LosTaskCB *taskCB) //用于打印任务的函数调用栈信息//
|
|
|
|
|
{
|
|
|
|
|
TaskContext *context = NULL;
|
|
|
|
|
|
|
|
|
@ -137,7 +138,7 @@ STATIC VOID OsDeadlockBackTrace(const LosTaskCB *taskCB)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC VOID OsMutexPendTaskList(LOS_DL_LIST *list)
|
|
|
|
|
STATIC VOID OsMutexPendTaskList(LOS_DL_LIST *list) //用于打印互斥锁等待任务的列表信息//
|
|
|
|
|
{
|
|
|
|
|
LOS_DL_LIST *listTmp = NULL;
|
|
|
|
|
LosTaskCB *pendedTask = NULL;
|
|
|
|
@ -168,7 +169,7 @@ STATIC VOID OsMutexPendTaskList(LOS_DL_LIST *list)
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC VOID OsTaskHoldMutexList(MuxDLinkCB *muxDLCB)
|
|
|
|
|
STATIC VOID OsTaskHoldMutexList(MuxDLinkCB *muxDLCB) //用于打印任务持有的互斥锁的信息//
|
|
|
|
|
{
|
|
|
|
|
UINT32 index = 0;
|
|
|
|
|
MuxDLinkNode *muxDLNode = NULL;
|
|
|
|
@ -204,7 +205,7 @@ STATIC VOID OsTaskHoldMutexList(MuxDLinkCB *muxDLCB)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID OsMutexDlockCheck(VOID)
|
|
|
|
|
VOID OsMutexDlockCheck(VOID) //用于检测互斥锁死锁情况并输出相关信息//
|
|
|
|
|
{
|
|
|
|
|
UINT32 loop, intSave;
|
|
|
|
|
UINT32 taskId;
|
|
|
|
@ -234,7 +235,7 @@ VOID OsMutexDlockCheck(VOID)
|
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef LOSCFG_SHELL
|
|
|
|
|
#ifdef LOSCFG_SHELL //用于在命令行中执行互斥锁死锁检查并输出相关信息//
|
|
|
|
|
UINT32 OsShellCmdMuxDeadlockCheck(UINT32 argc, const CHAR **argv)
|
|
|
|
|
{
|
|
|
|
|
if (argc > 0) {
|
|
|
|
|