summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2021-01-05 06:47:25 (GMT)
committer Hanhui <hanhui@acoinfo.com>2021-01-05 06:47:25 (GMT)
commita2a66ea40da08a260d930f9f21962c927025711d (patch)
tree66c2b49adf10abf4a3ccaea085c23bd4b74a30dd /SylixOS
parentafc5662654e446f422f4bef170b897f0c8f28b9e (diff)
downloadlibsylixos-a2a66ea40da08a260d930f9f21962c927025711d.zip
libsylixos-a2a66ea40da08a260d930f9f21962c927025711d.tar.gz
libsylixos-a2a66ea40da08a260d930f9f21962c927025711d.tar.bz2
VUTEX supports more matching types.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/arch/c6x/c6x_atomic.h3
-rw-r--r--SylixOS/kernel/include/k_option.h16
-rw-r--r--SylixOS/kernel/include/k_value.h1
-rw-r--r--SylixOS/kernel/vutex/vutex.c14
-rw-r--r--SylixOS/kernel/vutex/vutexLib.c36
5 files changed, 52 insertions, 18 deletions
diff --git a/SylixOS/arch/c6x/c6x_atomic.h b/SylixOS/arch/c6x/c6x_atomic.h
index 55e4d9d..04ffbbd 100644
--- a/SylixOS/arch/c6x/c6x_atomic.h
+++ b/SylixOS/arch/c6x/c6x_atomic.h
@@ -27,6 +27,9 @@
*********************************************************************************************************/
#if LW_CFG_CPU_ATOMIC_EN > 0
+/*********************************************************************************************************
+ No atomic support now!
+*********************************************************************************************************/
#endif /* LW_CFG_CPU_ATOMIC_EN */
#endif /* __ARCH_C6X_ATOMIC_H */
diff --git a/SylixOS/kernel/include/k_option.h b/SylixOS/kernel/include/k_option.h
index 56ddf50..8156b6d 100644
--- a/SylixOS/kernel/include/k_option.h
+++ b/SylixOS/kernel/include/k_option.h
@@ -269,13 +269,15 @@
VUTEX OPTIONS
*********************************************************************************************************/
/* 判断条件 */
-#define LW_OPTION_VUTEX_EQU 0 /* == */
-#define LW_OPTION_VUTEX_LESS 1 /* < */
-#define LW_OPTION_VUTEX_LESS_EQU 2 /* <= */
-#define LW_OPTION_VUTEX_GREATER 3 /* > */
-#define LW_OPTION_VUTEX_GREATER_EQU 4 /* >= */
-#define LW_OPTION_VUTEX_AND 5 /* & */
-#define LW_OPTION_VUTEX_NAND 6 /* &~ */
+#define LW_OPTION_VUTEX_EQU 0 /* value == desired */
+#define LW_OPTION_VUTEX_NOT_EQU 1 /* value != desired */
+#define LW_OPTION_VUTEX_LESS 2 /* value < desired */
+#define LW_OPTION_VUTEX_LESS_EQU 3 /* value <= desired */
+#define LW_OPTION_VUTEX_GREATER 4 /* value > desired */
+#define LW_OPTION_VUTEX_GREATER_EQU 5 /* value >= desired */
+#define LW_OPTION_VUTEX_AND 6 /* (value & desired) == desired*/
+#define LW_OPTION_VUTEX_NOT 8 /* (value & desired) == 0 */
+#define LW_OPTION_VUTEX_OR 7 /* (value & desired) != 0 */
/* PostEx Flags */
#define LW_OPTION_VUTEX_FLAG_WAKEALL 0x0001 /* 全部唤醒 */
diff --git a/SylixOS/kernel/include/k_value.h b/SylixOS/kernel/include/k_value.h
index 61b28e1..d3d0de1 100644
--- a/SylixOS/kernel/include/k_value.h
+++ b/SylixOS/kernel/include/k_value.h
@@ -171,6 +171,7 @@
#ifdef __SYLIXOS_KERNEL
#define LW_ACCESS_ONCE(type, x) (*(volatile type *)&(x))
+#define LW_ACCESS_ONCE_PTR(type, x) (*(volatile type *)(x))
#endif
#endif /* __K_VALUE_H */
diff --git a/SylixOS/kernel/vutex/vutex.c b/SylixOS/kernel/vutex/vutex.c
index f0df9d2..21f71ee 100644
--- a/SylixOS/kernel/vutex/vutex.c
+++ b/SylixOS/kernel/vutex/vutex.c
@@ -30,8 +30,8 @@
** 函数名称: API_VutexPendEx
** 功能描述: 等待一个变量到达某个值 (带有条件)
** 输 入 : piVar 等待的变量地址
-** iDesired 期望的数值
** iCompare 比较方法
+** iDesired 期望的数值
** ulTimeout 等待时间
** 输 出 : ERROR or 0: 被真实的等待值激活, 1: 被 WAKEALL 激活.
** 全局变量:
@@ -60,7 +60,8 @@ INT API_VutexPendEx (INT *piVar, INT iCompare, INT iDesired, ULONG ulTimeou
}
__wait_again:
- if (_VutexWakeIsMatch(*piVar, iCompare, iDesired)) { /* 是否已经满足条件 */
+ if (_VutexWakeIsMatch(LW_ACCESS_ONCE_PTR(INT, piVar),
+ iCompare, iDesired)) { /* 是否已经满足条件 */
return (ERROR_NONE);
} else if (ulTimeout == LW_OPTION_NOT_WAIT) { /* 不等待 */
@@ -69,7 +70,8 @@ __wait_again:
}
__KERNEL_ENTER(); /* 进入内核 */
- if (_VutexWakeIsMatch(*piVar, iCompare, iDesired)) {
+ if (_VutexWakeIsMatch(LW_ACCESS_ONCE_PTR(INT, piVar),
+ iCompare, iDesired)) { /* 在次确认是否已经满足条件 */
__KERNEL_EXIT();
return (ERROR_NONE);
}
@@ -171,14 +173,14 @@ INT API_VutexPostEx (INT *piVar, INT iValue, INT iFlags)
}
if (LW_VUTEX_POST_CHECK_VALUE(iFlags)) {
- if (*(volatile INT *)piVar == iValue) { /* 非全部唤醒且值已经相同 */
+ if (LW_ACCESS_ONCE_PTR(INT, piVar) == iValue) { /* 非全部唤醒且值已经相同 */
return (ERROR_NONE);
}
}
__KERNEL_ENTER(); /* 进入内核 */
if (LW_VUTEX_POST_CHECK_VALUE(iFlags)) {
- if (*(volatile INT *)piVar == iValue) {
+ if (LW_ACCESS_ONCE_PTR(INT, piVar) == iValue) {
__KERNEL_EXIT();
return (ERROR_NONE); /* 非全部唤醒且值已经相同 */
}
@@ -200,7 +202,7 @@ INT API_VutexPostEx (INT *piVar, INT iValue, INT iFlags)
}
if (!(iFlags & LW_OPTION_VUTEX_FLAG_DONTSET)) { /* 仅唤醒 */
- *(volatile INT *)piVar = iValue;
+ LW_ACCESS_ONCE_PTR(INT, piVar) = iValue;
KN_SMP_WMB();
}
diff --git a/SylixOS/kernel/vutex/vutexLib.c b/SylixOS/kernel/vutex/vutexLib.c
index 31f951b..ed28e12 100644
--- a/SylixOS/kernel/vutex/vutexLib.c
+++ b/SylixOS/kernel/vutex/vutexLib.c
@@ -23,16 +23,30 @@
/*********************************************************************************************************
宏定义
*********************************************************************************************************/
-#define LW_VUTEX_ALIGN_LOG 3
#define LW_VUTEX_HASH_SIZE 1024
#define LW_VUTEX_HASH_MASK 0x3ff
-#define LW_VUTEX_HASH_INDEX(a) (((a) >> LW_VUTEX_ALIGN_LOG) & LW_VUTEX_HASH_MASK)
+#define LW_VUTEX_HASH_INDEX(a) _VutexHash(a)
/*********************************************************************************************************
全局变量
*********************************************************************************************************/
static LW_LIST_LINE_HEADER _k_plineVutexHashHeader[LW_VUTEX_HASH_SIZE];
static PLW_LIST_LINE _k_plineVutexOp;
/*********************************************************************************************************
+** 函数名称: _VutexHash
+** 功能描述: 计算 vutex hash 值
+** 输 入 : phyaddr 物理地址
+** 输 出 : hash index
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_INLINE static UINT32 _VutexHash (phys_addr_t phyaddr)
+{
+ UINT32 uiTemp = (UINT32)(phyaddr >> 2);
+ REGISTER UINT8 *pucTemp = (UINT8 *)&uiTemp;
+
+ return ((pucTemp[0] + pucTemp[1] + pucTemp[2] + pucTemp[3]) & LW_VUTEX_HASH_MASK);
+}
+/*********************************************************************************************************
** 函数名称: _VutexWakeIsMatch
** 功能描述: 判断条件是否匹配
** 输 入 : iValue 真实数值
@@ -54,6 +68,12 @@ BOOL _VutexWakeIsMatch (INT iValue, INT iCompare, INT iDesired)
}
break;
+ case LW_OPTION_VUTEX_NOT_EQU:
+ if (iValue != iDesired) {
+ bMatch = LW_TRUE;
+ }
+ break;
+
case LW_OPTION_VUTEX_LESS:
if (iValue < iDesired) {
bMatch = LW_TRUE;
@@ -79,13 +99,19 @@ BOOL _VutexWakeIsMatch (INT iValue, INT iCompare, INT iDesired)
break;
case LW_OPTION_VUTEX_AND:
- if (iValue & iDesired) {
+ if ((iValue & iDesired) == iDesired) {
bMatch = LW_TRUE;
}
break;
- case LW_OPTION_VUTEX_NAND:
- if (~iValue & iDesired) {
+ case LW_OPTION_VUTEX_NOT:
+ if ((iValue & iDesired) == 0) {
+ bMatch = LW_TRUE;
+ }
+ break;
+
+ case LW_OPTION_VUTEX_OR:
+ if (iValue & iDesired) {
bMatch = LW_TRUE;
}
break;