summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-05-10 10:00:56 (GMT)
committer Hanhui <sylixos@gmail.com>2019-04-18 15:50:21 (GMT)
commite7f7e0875462ccd591148c2014c298119b778591 (patch)
tree4b9a11012dc45542170bf14dedc2e42996fbb9a7
parent914dfdd538c3a6a3b3516771fd6bb50d23455951 (diff)
downloadAIC-OS-e7f7e0875462ccd591148c2014c298119b778591.zip
Fixed atomic switch task state lock with LW_OPTION_DELETE_SAFE.
-rw-r--r--SylixOS/fs/iso9660Fs/iso9660_sylixos.c3
-rw-r--r--SylixOS/kernel/core/_ThreadSafeLib.c15
-rw-r--r--SylixOS/kernel/include/k_internal.h2
-rw-r--r--SylixOS/kernel/interface/SemaphoreMPend.c10
-rw-r--r--SylixOS/kernel/interface/SemaphoreMPost.c8
-rw-r--r--SylixOS/kernel/interface/SemaphoreRWPend.c21
-rw-r--r--SylixOS/kernel/interface/SemaphoreRWPost.c8
7 files changed, 44 insertions, 23 deletions
diff --git a/SylixOS/fs/iso9660Fs/iso9660_sylixos.c b/SylixOS/fs/iso9660Fs/iso9660_sylixos.c
index 9b0bd7b..5347146 100644
--- a/SylixOS/fs/iso9660Fs/iso9660_sylixos.c
+++ b/SylixOS/fs/iso9660Fs/iso9660_sylixos.c
@@ -688,7 +688,6 @@ ssize_t __iso9660FsRead (PLW_FD_ENTRY pfdentry,
__ISO_FILE_UNLOCK(pisofile);
- _ErrorHandle(ERROR_NONE);
return ((ssize_t)uiReadNum);
}
/*********************************************************************************************************
@@ -755,7 +754,6 @@ ssize_t __iso9660FsPRead (PLW_FD_ENTRY pfdentry,
__ISO_FILE_UNLOCK(pisofile);
- _ErrorHandle(ERROR_NONE);
return ((ssize_t)uiReadNum);
}
/*********************************************************************************************************
@@ -1161,7 +1159,6 @@ static INT __iso9660FsReadDir (PLW_FD_ENTRY pfdentry, DIR *dir)
__ISO_FILE_UNLOCK(pisofile);
- _ErrorHandle(ERROR_NONE);
return (ERROR_NONE);
}
/*********************************************************************************************************
diff --git a/SylixOS/kernel/core/_ThreadSafeLib.c b/SylixOS/kernel/core/_ThreadSafeLib.c
index 69ae3ac..18671de 100644
--- a/SylixOS/kernel/core/_ThreadSafeLib.c
+++ b/SylixOS/kernel/core/_ThreadSafeLib.c
@@ -101,6 +101,21 @@ VOID _ThreadSafeInternal (VOID)
ptcbCur->TCB_ulId, ptcbCur->TCB_ulThreadSafeCounter, LW_NULL);
}
/*********************************************************************************************************
+** 函数名称: _ThreadSafeInKern
+** 功能描述: 在内核模式指定线程进入安全模式 (内核锁定状态被调用)
+** 输 入 : ptcbDes 目标线程
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID _ThreadSafeInKern (PLW_CLASS_TCB ptcbDes)
+{
+ ptcbDes->TCB_ulThreadSafeCounter++;
+
+ MONITOR_EVT_LONG2(MONITOR_EVENT_ID_THREAD, MONITOR_EVENT_THREAD_SAFE,
+ ptcbDes->TCB_ulId, ptcbDes->TCB_ulThreadSafeCounter, LW_NULL);
+}
+/*********************************************************************************************************
** 函数名称: _ThreadUnsafeInternal
** 功能描述: 当前线程进入安全模式
** 输 入 : NONE
diff --git a/SylixOS/kernel/include/k_internal.h b/SylixOS/kernel/include/k_internal.h
index 6a2a374..cec6154 100644
--- a/SylixOS/kernel/include/k_internal.h
+++ b/SylixOS/kernel/include/k_internal.h
@@ -501,10 +501,12 @@ VOID _ThreadUnlock(VOID);
VOID _ThreadSafeSuspend(PLW_CLASS_TCB ptcbCur);
VOID _ThreadSafeResume(PLW_CLASS_TCB ptcb);
VOID _ThreadSafeInternal(VOID);
+VOID _ThreadSafeInKern(PLW_CLASS_TCB ptcbDes);
VOID _ThreadUnsafeInternal(VOID);
VOID _ThreadUnsafeInternalEx(PLW_CLASS_TCB ptcbDes);
#define LW_THREAD_SAFE() _ThreadSafeInternal()
+#define LW_THREAD_SAFE_INKERN(ptcb) _ThreadSafeInKern(ptcb)
#define LW_THREAD_UNSAFE() _ThreadUnsafeInternal()
#define LW_THREAD_UNSAFE_EX(ptcb) _ThreadUnsafeInternalEx(ptcb)
diff --git a/SylixOS/kernel/interface/SemaphoreMPend.c b/SylixOS/kernel/interface/SemaphoreMPend.c
index 1412e31..84d9826 100644
--- a/SylixOS/kernel/interface/SemaphoreMPend.c
+++ b/SylixOS/kernel/interface/SemaphoreMPend.c
@@ -42,6 +42,7 @@
2013.07.18 使用新的获取 TCB 的方法, 确保 SMP 系统安全.
2013.12.11 系统没有启动时 pend 操作不工作.
2014.05.29 修复超时后瞬间激活时没有设置任务安全属性错误.
+2019.05.10 安全模式设置必须与获取处于同一原子状态.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -132,10 +133,10 @@ __wait_again:
pevent->EVENT_ulCounter = LW_FALSE;
pevent->EVENT_ulMaxCounter = (ULONG)ptcbCur->TCB_ucPriority;
pevent->EVENT_pvTcbOwn = (PVOID)ptcbCur; /* 保存线程信息 */
- __KERNEL_EXIT(); /* 退出内核 */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
+ LW_THREAD_SAFE_INKERN(ptcbCur);
}
+ __KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
}
@@ -213,10 +214,7 @@ __wait_again:
} else {
if (ptcbCur->TCB_ucIsEventDelete == LW_EVENT_EXIST) { /* 事件是否存在 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
- }
- return (ERROR_NONE);
+ return (ERROR_NONE); /* 释放操作已将此任务设为安全 */
} else {
_ErrorHandle(ERROR_EVENT_WAS_DELETED); /* 已经被删除 */
diff --git a/SylixOS/kernel/interface/SemaphoreMPost.c b/SylixOS/kernel/interface/SemaphoreMPost.c
index 0fe86c1..4f7ba41 100644
--- a/SylixOS/kernel/interface/SemaphoreMPost.c
+++ b/SylixOS/kernel/interface/SemaphoreMPost.c
@@ -130,12 +130,16 @@ ULONG API_SemaphoreMPost (LW_OBJECT_HANDLE ulId)
_EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) {
+ LW_THREAD_SAFE_INKERN(ptcb); /* 将激活任务设置为安全 */
+ }
+
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMM, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
__KERNEL_EXIT(); /* 退出内核 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 退出安全模式 */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 本任务退出安全模式 */
LW_THREAD_UNSAFE();
}
return (ERROR_NONE);
@@ -151,7 +155,7 @@ ULONG API_SemaphoreMPost (LW_OBJECT_HANDLE ulId)
__KERNEL_EXIT(); /* 退出内核 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 退出安全模式 */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 本任务退出安全模式 */
LW_THREAD_UNSAFE();
}
return (ERROR_NONE);
diff --git a/SylixOS/kernel/interface/SemaphoreRWPend.c b/SylixOS/kernel/interface/SemaphoreRWPend.c
index 76d1d37..d619ba9 100644
--- a/SylixOS/kernel/interface/SemaphoreRWPend.c
+++ b/SylixOS/kernel/interface/SemaphoreRWPend.c
@@ -17,6 +17,9 @@
** 文件创建日期: 2016 年 07 月 20 日
**
** 描 述: 等待读写信号量.
+**
+** BUG
+2019.05.10 安全模式设置必须与获取处于同一原子状态.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -98,10 +101,10 @@ __wait_again:
if ((pevent->EVENT_iStatus == EVENT_RW_STATUS_R) &&
(_EventWaitNum(EVENT_RW_Q_W, pevent) == 0)) { /* 当前为读状态并且没有写请求 */
pevent->EVENT_ulCounter++; /* 操作数++ */
- __KERNEL_EXIT(); /* 退出内核 */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
+ LW_THREAD_SAFE_INKERN(ptcbCur);
}
+ __KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
}
@@ -163,10 +166,7 @@ __wait_again:
} else {
if (ptcbCur->TCB_ucIsEventDelete == LW_EVENT_EXIST) { /* 事件是否存在 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
- }
- return (ERROR_NONE);
+ return (ERROR_NONE); /* 释放操作已将此任务设为安全 */
} else {
_ErrorHandle(ERROR_EVENT_WAS_DELETED); /* 已经被删除 */
@@ -243,10 +243,10 @@ __wait_again:
pevent->EVENT_ulCounter++;
pevent->EVENT_iStatus = EVENT_RW_STATUS_W;
pevent->EVENT_pvTcbOwn = (PVOID)ptcbCur; /* 保存线程信息 */
- __KERNEL_EXIT(); /* 退出内核 */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
+ LW_THREAD_SAFE_INKERN(ptcbCur);
}
+ __KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
}
@@ -314,10 +314,7 @@ __wait_again:
} else {
if (ptcbCur->TCB_ucIsEventDelete == LW_EVENT_EXIST) { /* 事件是否存在 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
- }
- return (ERROR_NONE);
+ return (ERROR_NONE); /* 释放操作已将此任务设为安全 */
} else {
_ErrorHandle(ERROR_EVENT_WAS_DELETED); /* 已经被删除 */
diff --git a/SylixOS/kernel/interface/SemaphoreRWPost.c b/SylixOS/kernel/interface/SemaphoreRWPost.c
index e02e8ee..c1ef8bd 100644
--- a/SylixOS/kernel/interface/SemaphoreRWPost.c
+++ b/SylixOS/kernel/interface/SemaphoreRWPost.c
@@ -136,6 +136,10 @@ __release_pend:
pevent->EVENT_pvTcbOwn = (PVOID)ptcb;
pevent->EVENT_iStatus = EVENT_RW_STATUS_W;
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 将激活任务设置为安全 */
+ LW_THREAD_SAFE_INKERN(ptcb);
+ }
+
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMRW, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
@@ -164,6 +168,10 @@ __release_pend:
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
_EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 将激活任务设置为安全 */
+ LW_THREAD_SAFE_INKERN(ptcb);
+ }
+
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMRW, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);