summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-06-28 08:49:06 (GMT)
committer Hanhui <sylixos@gmail.com>2019-06-19 09:03:43 (GMT)
commitfac14cbfadae21b9af6d4d72397bf47c5eec3fcf (patch)
tree98743319521d2556d19e87ee3c2bbffabc904068
parentc6a85524f36f04e32a0e4664e90ff190d00055cc (diff)
downloadAIC-OS-fac14cbfadae21b9af6d4d72397bf47c5eec3fcf.zip
Fixed some POSIX interfaces to conform to standard definitions.
-rw-r--r--SylixOS/fs/tpsFs/tpsfs_sylixos.c14
-rw-r--r--SylixOS/kernel/include/k_kernel.h2
-rw-r--r--SylixOS/loader/include/loader_vppatch.h11
-rw-r--r--SylixOS/loader/src/loader_vpthread.c41
-rw-r--r--SylixOS/posix/sched/sched.c96
5 files changed, 128 insertions, 36 deletions
diff --git a/SylixOS/fs/tpsFs/tpsfs_sylixos.c b/SylixOS/fs/tpsFs/tpsfs_sylixos.c
index 934500c..a5605b6 100644
--- a/SylixOS/fs/tpsFs/tpsfs_sylixos.c
+++ b/SylixOS/fs/tpsFs/tpsfs_sylixos.c
@@ -1164,11 +1164,12 @@ static ssize_t __tpsFsWrite (PLW_FD_ENTRY pfdentry,
break;
}
}
+ __SHEAP_FREE(pucZoreBuf);
- __SHEAP_FREE(pucZoreBuf);
- if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < pfdentry->FDENTRY_oftPtr) {
+ pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+ if (pfdnode->FDNODE_oftSize < pfdentry->FDENTRY_oftPtr) {
__TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(EFBIG);
+ _ErrorHandle(ENOSPC);
return (PX_ERROR);
}
}
@@ -1244,11 +1245,12 @@ static ssize_t __tpsFsPWrite (PLW_FD_ENTRY pfdentry,
break;
}
}
+ __SHEAP_FREE(pucZoreBuf);
- __SHEAP_FREE(pucZoreBuf);
- if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftPos) {
+ pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+ if (pfdnode->FDNODE_oftSize < oftPos) {
__TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(EFBIG);
+ _ErrorHandle(ENOSPC);
return (PX_ERROR);
}
}
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index d48364b..b08c77e 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -51,7 +51,7 @@
#define __SYLIXOS_MAJOR_VER 1
#define __SYLIXOS_MINOR_VER 10
-#define __SYLIXOS_PATCH_VER 0
+#define __SYLIXOS_PATCH_VER 1
#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
diff --git a/SylixOS/loader/include/loader_vppatch.h b/SylixOS/loader/include/loader_vppatch.h
index a5d57e2..16a7840 100644
--- a/SylixOS/loader/include/loader_vppatch.h
+++ b/SylixOS/loader/include/loader_vppatch.h
@@ -206,9 +206,18 @@ INT vprocMemInfoNoLock(LW_LD_VPROC *pvproc,
VOID vprocThreadAdd(PVOID pvVProc, PLW_CLASS_TCB ptcb);
VOID vprocThreadDelete(PVOID pvVProc, PLW_CLASS_TCB ptcb);
-INT vprocThreadNum(pid_t pid, ULONG *pulNum);
VOID vprocThreadKill(PVOID pvVProc, PLW_CLASS_TCB ptcbExcp);
+INT vprocThreadNum(pid_t pid, ULONG *pulNum);
+INT vprocThreadTraversal(pid_t pid,
+ VOIDFUNCPTR pfunc,
+ PVOID pvArg0,
+ PVOID pvArg1,
+ PVOID pvArg2,
+ PVOID pvArg3,
+ PVOID pvArg4,
+ PVOID pvArg5);
+
#if LW_CFG_SIGNAL_EN > 0
INT vprocThreadSigaction(PVOID pvVProc, VOIDFUNCPTR pfunc, INT iSigIndex,
const struct sigaction *psigactionNew);
diff --git a/SylixOS/loader/src/loader_vpthread.c b/SylixOS/loader/src/loader_vpthread.c
index e48a7b4..9753fe9 100644
--- a/SylixOS/loader/src/loader_vpthread.c
+++ b/SylixOS/loader/src/loader_vpthread.c
@@ -133,6 +133,47 @@ VOID vprocThreadKill (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
LW_VP_UNLOCK(pvproc); /* 解锁当前进程 */
}
/*********************************************************************************************************
+** 函数名称: vprocThreadTraversal
+** 功能描述: 遍历进程内的所有线程 (为了提高效率此函数会锁定 KERNEL)
+** 输 入 : pid 进程 id
+** pfunc 回调函数
+** pvArg[0 ~ 5] 遍历函数参数
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT vprocThreadTraversal (pid_t pid,
+ VOIDFUNCPTR pfunc,
+ PVOID pvArg0,
+ PVOID pvArg1,
+ PVOID pvArg2,
+ PVOID pvArg3,
+ PVOID pvArg4,
+ PVOID pvArg5)
+{
+ LW_LD_VPROC *pvproc;
+ PLW_LIST_LINE plineTemp;
+ PLW_CLASS_TCB ptcb;
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ pvproc = vprocGet(pid);
+ if (!pvproc) {
+ __KERNEL_EXIT(); /* 退出内核 */
+ return (PX_ERROR);
+ }
+
+ for (plineTemp = pvproc->VP_plineThread;
+ plineTemp != LW_NULL;
+ plineTemp = _list_line_get_next(plineTemp)) {
+
+ ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ pfunc(ptcb, pvArg0, pvArg1, pvArg2, pvArg3, pvArg4, pvArg5);
+ }
+ __KERNEL_EXIT(); /* 退出内核 */
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
** 函数名称: vprocThreadSigaction
** 功能描述: 设置进程内所有任务的 sigaction
** 输 入 : pvVProc 进程控制块指针
diff --git a/SylixOS/posix/sched/sched.c b/SylixOS/posix/sched/sched.c
index 49e6d10..1edaf70 100644
--- a/SylixOS/posix/sched/sched.c
+++ b/SylixOS/posix/sched/sched.c
@@ -90,6 +90,36 @@ int sched_yield (void)
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: __sched_set
+** 功能描述: 设置指定任务调度器参数 (进入内核后被调用)
+** 输 入 : ptcb 任务控制块
+** pucPolicy 调度策略
+** pucPriority 优先级
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+
+static VOID __sched_set (PLW_CLASS_TCB ptcb, UINT8 *pucPolicy, UINT8 *pucPriority)
+{
+ if (pucPriority) {
+ if (!LW_PRIO_IS_EQU(ptcb->TCB_ucPriority, *pucPriority)) {
+ _SchedSetPrio(ptcb, *pucPriority);
+ }
+ }
+
+ if (pucPolicy) {
+ ptcb->TCB_ucSchedPolicy = *pucPolicy;
+ if (*pucPolicy == LW_OPTION_SCHED_FIFO) {
+ ptcb->TCB_usSchedCounter = ptcb->TCB_usSchedSlice; /* 不为零 */
+ }
+ }
+}
+
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
** 函数名称: sched_setparam
** 功能描述: 设置指定任务调度器参数
** 输 入 : pid 进程 / 线程 ID
@@ -102,9 +132,7 @@ int sched_yield (void)
LW_API
int sched_setparam (pid_t pid, const struct sched_param *pschedparam)
{
- UINT8 ucPriority;
- ULONG ulError;
- LW_OBJECT_HANDLE ulThread;
+ UINT8 ucPriority;
if (pschedparam == LW_NULL) {
errno = EINVAL;
@@ -120,29 +148,29 @@ int sched_setparam (pid_t pid, const struct sched_param *pschedparam)
#if LW_CFG_MODULELOADER_EN > 0
if (pid == 0) {
- pid = getpid();
+ pid = getpid();
}
if (pid == 0) {
- ulThread = API_ThreadIdSelf();
- } else {
- ulThread = vprocMainThread(pid);
+ errno = ESRCH;
+ return (PX_ERROR);
}
- if (ulThread == LW_OBJECT_HANDLE_INVALID) {
+
+ if (vprocThreadTraversal(pid, __sched_set, LW_NULL, &ucPriority,
+ LW_NULL, LW_NULL, LW_NULL, LW_NULL)) {
errno = ESRCH;
return (PX_ERROR);
}
#else
- ulThread = (LW_OBJECT_HANDLE)pid;
+ LW_OBJECT_HANDLE ulThread = (LW_OBJECT_HANDLE)pid;
PX_ID_VERIFY(ulThread, LW_OBJECT_HANDLE);
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
- ulError = API_ThreadSetPriority(ulThread, ucPriority);
- if (ulError) {
+ if (API_ThreadSetPriority(ulThread, ucPriority)) {
errno = ESRCH;
return (PX_ERROR);
- } else {
- return (ERROR_NONE);
}
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: sched_getparam
@@ -209,9 +237,7 @@ int sched_setscheduler (pid_t pid,
int iPolicy,
const struct sched_param *pschedparam)
{
- UINT8 ucPriority;
- UINT8 ucActivatedMode;
- LW_OBJECT_HANDLE ulThread;
+ UINT8 ucPriority;
if (pschedparam == LW_NULL) {
errno = EINVAL;
@@ -234,21 +260,22 @@ int sched_setscheduler (pid_t pid,
#if LW_CFG_MODULELOADER_EN > 0
if (pid == 0) {
- pid = getpid();
+ pid = getpid();
}
if (pid == 0) {
- ulThread = API_ThreadIdSelf();
- } else {
- ulThread = vprocMainThread(pid);
+ errno = ESRCH;
+ return (PX_ERROR);
}
- if (ulThread == LW_OBJECT_HANDLE_INVALID) {
+
+ if (vprocThreadTraversal(pid, __sched_set, &iPolicy, &ucPriority,
+ LW_NULL, LW_NULL, LW_NULL, LW_NULL)) {
errno = ESRCH;
return (PX_ERROR);
}
#else
- ulThread = (LW_OBJECT_HANDLE)pid;
+ UINT8 ucActivatedMode;
+ LW_OBJECT_HANDLE ulThread = (LW_OBJECT_HANDLE)pid;
PX_ID_VERIFY(ulThread, LW_OBJECT_HANDLE);
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
if (API_ThreadGetSchedParam(ulThread,
LW_NULL,
@@ -256,15 +283,16 @@ int sched_setscheduler (pid_t pid,
errno = ESRCH;
return (PX_ERROR);
}
-
+
API_ThreadSetSchedParam(ulThread, (UINT8)iPolicy, ucActivatedMode);
-
+
if (API_ThreadSetPriority(ulThread, ucPriority)) {
errno = ESRCH;
return (PX_ERROR);
- } else {
- return (ERROR_NONE);
}
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: sched_getscheduler
@@ -387,10 +415,16 @@ int sched_setaffinity (pid_t pid, size_t setsize, const cpu_set_t *set)
errno = EINVAL;
return (PX_ERROR);
}
+
+#if LW_CFG_MODULELOADER_EN > 0
if (vprocSetAffinity(pid, setsize, (PLW_CLASS_CPUSET)set)) {
errno = ESRCH;
return (PX_ERROR);
}
+#else
+ errno = ESRCH;
+ return (PX_ERROR);
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
#endif /* LW_CFG_SMP_EN > 0 */
return (ERROR_NONE);
@@ -414,10 +448,16 @@ int sched_getaffinity (pid_t pid, size_t setsize, cpu_set_t *set)
errno = EINVAL;
return (PX_ERROR);
}
+
+#if LW_CFG_MODULELOADER_EN > 0
if (vprocGetAffinity(pid, setsize, set)) {
errno = ESRCH;
return (PX_ERROR);
}
+#else
+ errno = ESRCH;
+ return (PX_ERROR);
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
#endif /* LW_CFG_SMP_EN > 0 */
return (ERROR_NONE);