/********************************************************************************************************* ** 函数名称: _SmpSpinTryLock ** 功能描述: 自旋锁尝试加锁操作 ** 输 入 : psl 自旋锁 ** 输 出 : LW_TRUE 加锁正常 LW_FALSE 加锁失败 ** 全局变量: ** 调用模块: *********************************************************************************************************/ BOOL _SmpSpinTryLock (spinlock_t *psl) { INTREG iregInterLevel; PLW_CLASS_CPU pcpuCur; INT iRet; iregInterLevel = KN_INT_DISABLE(); pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } LW_CPU_SPIN_NESTING_INC(pcpuCur); iRet = __ARCH_SPIN_TRYLOCK(psl); KN_SMP_MB(); if (iRet != LW_SPIN_OK) { if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_DEC(pcpuCur->CPU_ptcbTCBCur); /* 解锁失败, 解除任务锁定 */ } LW_CPU_SPIN_NESTING_DEC(pcpuCur); } KN_INT_ENABLE(iregInterLevel); return ((iRet == LW_SPIN_OK) ? (LW_TRUE) : (LW_FALSE)); }
/********************************************************************************************************* ** 函数名称: _UpSpinLockIgnIrq ** 功能描述: 内核自旋锁加锁操作, 忽略中断锁定 (必须在中断关闭的状态下被调用) ** 输 入 : NONE ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _UpKernelLockIgnIrq (VOID) { PLW_CLASS_CPU pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } }
/********************************************************************************************************* ** 函数名称: _UpSpinLock ** 功能描述: 自旋锁加锁操作 ** 输 入 : psl 自旋锁 ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _UpSpinLock (spinlock_t *psl) { PLW_CLASS_CPU pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } }
/********************************************************************************************************* ** 函数名称: _UpKernelLockQuick ** 功能描述: 内核自旋锁加锁操作, 连同锁定中断 ** 输 入 : piregInterLevel 中断锁定信息 ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _UpKernelLockQuick (INTREG *piregInterLevel) { PLW_CLASS_CPU pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } *piregInterLevel = KN_INT_DISABLE(); }
/********************************************************************************************************* ** 函数名称: _UpSpinTryLock ** 功能描述: 自旋锁尝试加锁操作 ** 输 入 : psl 自旋锁 ** 输 出 : LW_TRUE 加锁正常 LW_FALSE 加锁失败 ** 全局变量: ** 调用模块: *********************************************************************************************************/ BOOL _UpSpinTryLock (spinlock_t *psl) { PLW_CLASS_CPU pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } return (LW_TRUE); }
/********************************************************************************************************* ** 函数名称: _UpSpinLockIrq ** 功能描述: 自旋锁加锁操作, 连同锁定中断 ** 输 入 : psl 自旋锁 ** piregInterLevel 中断锁定信息 ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _UpSpinLockIrq (spinlock_t *psl, INTREG *piregInterLevel) { PLW_CLASS_CPU pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } *piregInterLevel = KN_INT_DISABLE(); }
/********************************************************************************************************* ** 函数名称: _SmpSpinLockIgnIrq ** 功能描述: 自旋锁加锁操作, 忽略中断锁定 (必须在中断关闭的状态下被调用) ** 输 入 : psl 自旋锁 ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _SmpSpinLockIgnIrq (spinlock_t *psl) { PLW_CLASS_CPU pcpuCur; pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } LW_CPU_SPIN_NESTING_INC(pcpuCur); __ARCH_SPIN_LOCK(psl); /* 驱动保证锁定必须成功 */ KN_SMP_MB(); }
/********************************************************************************************************* ** 函数名称: _SmpSpinLockTask ** 功能描述: 自旋锁原始加锁操作. (不锁定中断, 同时允许加锁后调用可能产生阻塞的操作) ** 输 入 : psl 自旋锁 ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _SmpSpinLockTask (spinlock_t *psl) { INTREG iregInterLevel; PLW_CLASS_CPU pcpuCur; iregInterLevel = KN_INT_DISABLE(); pcpuCur = LW_CPU_GET_CUR(); _BugHandle(pcpuCur->CPU_ulInterNesting, LW_TRUE, "called from ISR.\r\n"); __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ __ARCH_SPIN_LOCK_RAW(psl); /* 驱动保证锁定必须成功 */ KN_SMP_MB(); KN_INT_ENABLE(iregInterLevel); }
/********************************************************************************************************* ** 函数名称: _SmpSpinLock ** 功能描述: 自旋锁加锁操作 ** 输 入 : psl 自旋锁 ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ VOID _SmpSpinLock (spinlock_t *psl) { INTREG iregInterLevel; PLW_CLASS_CPU pcpuCur; iregInterLevel = KN_INT_DISABLE(); pcpuCur = LW_CPU_GET_CUR(); if (!pcpuCur->CPU_ulInterNesting) { __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ } LW_CPU_SPIN_NESTING_INC(pcpuCur); __ARCH_SPIN_LOCK(psl); /* 驱动保证锁定必须成功 */ KN_SMP_MB(); KN_INT_ENABLE(iregInterLevel); }
/********************************************************************************************************* ** 函数名称: _SmpSpinTryLockTask ** 功能描述: 自旋锁尝试原始加锁操作. (不锁定中断, 同时允许加锁后调用可能产生阻塞的操作) ** 输 入 : psl 自旋锁 ** 输 出 : LW_TRUE 加锁正常 LW_FALSE 加锁失败 ** 全局变量: ** 调用模块: *********************************************************************************************************/ BOOL _SmpSpinTryLockTask (spinlock_t *psl) { INTREG iregInterLevel; PLW_CLASS_CPU pcpuCur; INT iRet; iregInterLevel = KN_INT_DISABLE(); pcpuCur = LW_CPU_GET_CUR(); _BugHandle(pcpuCur->CPU_ulInterNesting, LW_TRUE, "called from ISR.\r\n"); __THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */ iRet = __ARCH_SPIN_TRYLOCK_RAW(psl); KN_SMP_MB(); if (iRet != LW_SPIN_OK) { __THREAD_LOCK_DEC(pcpuCur->CPU_ptcbTCBCur); /* 解锁失败, 解除任务锁定 */ } KN_INT_ENABLE(iregInterLevel); return ((iRet == LW_SPIN_OK) ? (LW_TRUE) : (LW_FALSE)); }