summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2021-01-03 13:03:00 (GMT)
committer Hanhui <hanhui@acoinfo.com>2021-01-03 13:03:00 (GMT)
commitafc5662654e446f422f4bef170b897f0c8f28b9e (patch)
treef8fa87430aaa8d6acf4a15e86ef3929da3c258ed /SylixOS
parent3fa8b96ef18230811c60c686610441c52f1985c1 (diff)
downloadlibsylixos-afc5662654e446f422f4bef170b897f0c8f28b9e.zip
libsylixos-afc5662654e446f422f4bef170b897f0c8f28b9e.tar.gz
libsylixos-afc5662654e446f422f4bef170b897f0c8f28b9e.tar.bz2
Optimize the speed of obtaining the current thread id.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/kernel/interface/ThreadIdSelf.c56
-rw-r--r--SylixOS/posix/pthread/pthread.c4
2 files changed, 51 insertions, 9 deletions
diff --git a/SylixOS/kernel/interface/ThreadIdSelf.c b/SylixOS/kernel/interface/ThreadIdSelf.c
index 98c4020..3d64d37 100644
--- a/SylixOS/kernel/interface/ThreadIdSelf.c
+++ b/SylixOS/kernel/interface/ThreadIdSelf.c
@@ -40,15 +40,36 @@
LW_API
LW_OBJECT_HANDLE API_ThreadIdSelf (VOID)
{
+ PLW_CLASS_CPU pcpuCur;
PLW_CLASS_TCB ptcbCur;
- if (LW_CPU_GET_CUR_NESTING()) { /* 不能在中断中调用 */
+#if LW_CFG_SMP_EN > 0
+ INTREG iregInterLevel;
+
+ iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
+
+ pcpuCur = LW_CPU_GET_CUR();
+ if (pcpuCur->CPU_ulInterNesting) {
+ KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
+ _ErrorHandle(ERROR_KERNEL_IN_ISR);
+ return (LW_OBJECT_HANDLE_INVALID);
+ }
+
+ ptcbCur = pcpuCur->CPU_ptcbTCBCur; /* 当前线程 */
+
+ KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
+
+#else /* LW_CFG_SMP_EN > 0 */
+ pcpuCur = LW_CPU_GET_CUR();
+ if (pcpuCur->CPU_ulInterNesting) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
_ErrorHandle(ERROR_KERNEL_IN_ISR);
- return (0);
+ return (LW_OBJECT_HANDLE_INVALID);
}
- LW_TCB_GET_CUR_SAFE(ptcbCur);
+ ptcbCur = pcpuCur->CPU_ptcbTCBCur; /* 当前线程 */
+#endif /* LW_CFG_SMP_EN == 0 */
return (ptcbCur->TCB_ulId);
}
@@ -100,15 +121,36 @@ LW_OBJECT_HANDLE API_ThreadIdSelfFast (VOID)
LW_API
PLW_CLASS_TCB API_ThreadTcbSelf (VOID)
{
+ PLW_CLASS_CPU pcpuCur;
PLW_CLASS_TCB ptcbCur;
- if (LW_CPU_GET_CUR_NESTING()) { /* 不能在中断中调用 */
+#if LW_CFG_SMP_EN > 0
+ INTREG iregInterLevel;
+
+ iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
+
+ pcpuCur = LW_CPU_GET_CUR();
+ if (pcpuCur->CPU_ulInterNesting) {
+ KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
_ErrorHandle(ERROR_KERNEL_IN_ISR);
- return (LW_NULL);
+ return (LW_OBJECT_HANDLE_INVALID);
}
-
- LW_TCB_GET_CUR_SAFE(ptcbCur);
+
+ ptcbCur = pcpuCur->CPU_ptcbTCBCur; /* 当前线程 */
+
+ KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
+
+#else /* LW_CFG_SMP_EN > 0 */
+ pcpuCur = LW_CPU_GET_CUR();
+ if (pcpuCur->CPU_ulInterNesting) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
+ _ErrorHandle(ERROR_KERNEL_IN_ISR);
+ return (LW_OBJECT_HANDLE_INVALID);
+ }
+
+ ptcbCur = pcpuCur->CPU_ptcbTCBCur; /* 当前线程 */
+#endif /* LW_CFG_SMP_EN == 0 */
return (ptcbCur);
}
diff --git a/SylixOS/posix/pthread/pthread.c b/SylixOS/posix/pthread/pthread.c
index 01917e4..b6b53a7 100644
--- a/SylixOS/posix/pthread/pthread.c
+++ b/SylixOS/posix/pthread/pthread.c
@@ -379,7 +379,7 @@ void pthread_exit (void *status)
LW_API
pthread_t pthread_self (void)
{
- return (API_ThreadIdSelf());
+ return (API_ThreadIdSelfFast());
}
/*********************************************************************************************************
** 函数名称: pthread_yield
@@ -393,7 +393,7 @@ pthread_t pthread_self (void)
LW_API
int pthread_yield (void)
{
- API_ThreadYield(API_ThreadIdSelf());
+ API_ThreadYield(API_ThreadIdSelfFast());
return (ERROR_NONE);
}