summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-04-22 09:20:11 (GMT)
committer Hanhui <sylixos@gmail.com>2019-04-18 15:47:53 (GMT)
commiteaed3abbc627f342c1141bd2d9d80ece7d60d0c8 (patch)
treeed8ee8b0c3bf44772670efa586790757de8e9a6b
parent64a4ad527dad1255148c36f103dfc72d75445714 (diff)
downloadAIC-OS-eaed3abbc627f342c1141bd2d9d80ece7d60d0c8.zip
Add posix thread init function and add process child, brother determine.
-rw-r--r--SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c4
-rw-r--r--SylixOS/include/sys/wait.h2
-rw-r--r--SylixOS/loader/src/loader_wait.c66
-rw-r--r--SylixOS/posix/include/px_pthread.h4
-rw-r--r--SylixOS/posix/include/px_pthread_np.h1
-rw-r--r--SylixOS/posix/pthread/pthread.c36
-rw-r--r--SylixOS/posix/pthread/pthread_attr.c59
-rw-r--r--SylixOS/system/signal/signalLib.c4
8 files changed, 171 insertions, 5 deletions
diff --git a/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c b/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c
index caad1ac..3f23695 100644
--- a/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c
+++ b/SylixOS/arch/arm/common/v7m/armExcV7MPendSv.c
@@ -35,9 +35,11 @@
*********************************************************************************************************/
VOID armv7mIntHandle (UINT32 uiVector)
{
- archIntEnableForce(); /* 打开中断, 允许嵌套 */
+ KN_INT_ENABLE_FORCE(); /* 打开中断, 允许嵌套 */
API_InterVectorIsr((ULONG)uiVector);
+
+ KN_INT_DISABLE(); /* 禁能中断 */
}
/*********************************************************************************************************
** 函数名称: armv7mNMIIntHandle
diff --git a/SylixOS/include/sys/wait.h b/SylixOS/include/sys/wait.h
index 71b1086..b7e48cf 100644
--- a/SylixOS/include/sys/wait.h
+++ b/SylixOS/include/sys/wait.h
@@ -82,6 +82,8 @@ pid_t wait4(pid_t pid, int *stat_loc, int options, struct rusage *prusage);
SylixOS extern API.
*********************************************************************************************************/
+BOOL ischild(pid_t pid);
+BOOL isbrother(pid_t pid);
void reclaimchild(pid_t pid);
int detach(pid_t pid);
diff --git a/SylixOS/loader/src/loader_wait.c b/SylixOS/loader/src/loader_wait.c
index 6f4a0bc..256a14e 100644
--- a/SylixOS/loader/src/loader_wait.c
+++ b/SylixOS/loader/src/loader_wait.c
@@ -696,6 +696,69 @@ void reclaimchild (pid_t pid)
} while (1);
}
/*********************************************************************************************************
+** 函数名称: ischild
+** 功能描述: 是否为当前进程子进程
+** 输 入 : pid 进程 ID
+** 输 出 : LW_TRUE: 是当前进程子进程, LW_FALSE 否
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+BOOL ischild (pid_t pid)
+{
+ LW_LD_VPROC *pvproc = __LW_VP_GET_CUR_PROC();
+
+ if (pvproc == LW_NULL) {
+ return (LW_FALSE);
+ }
+
+ return (__haveThisChild(pvproc, pid));
+}
+/*********************************************************************************************************
+** 函数名称: isbrother
+** 功能描述: 是否为当前进程兄弟进程
+** 输 入 : pid 进程 ID
+** 输 出 : LW_TRUE: 是当前进程兄弟进程, LW_FALSE 否
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+BOOL isbrother (pid_t pid)
+{
+ BOOL bRet = LW_FALSE;
+ LW_LD_VPROC *pvproc = __LW_VP_GET_CUR_PROC();
+ LW_LD_VPROC *pvprocChild;
+ LW_LD_VPROC *pvprocFather;
+ PLW_LIST_LINE plineList;
+
+ if (pvproc == LW_NULL) {
+ return (LW_FALSE);
+ }
+
+ LW_LD_LOCK();
+ pvprocFather = pvproc->VP_pvprocFather;
+ if (!pvprocFather) {
+ LW_LD_UNLOCK();
+ return (LW_FALSE);
+ }
+
+ for (plineList = pvprocFather->VP_plineChild;
+ plineList != LW_NULL;
+ plineList = _list_line_get_next(plineList)) {
+
+ pvprocChild = _LIST_ENTRY(plineList, LW_LD_VPROC, VP_lineBrother);
+ if (pvprocChild->VP_pid == pid) {
+ bRet = LW_TRUE;
+ break;
+ }
+ }
+ LW_LD_UNLOCK();
+
+ return (bRet);
+}
+/*********************************************************************************************************
** 函数名称: detach
** 功能描述: 脱离与父进程关系
** 输 入 : pid 指定的子线程
@@ -756,7 +819,6 @@ int daemon (int nochdir, int noclose)
return (ERROR_NONE);
}
-#else /* NO MODULELOADER */
/*********************************************************************************************************
** 函数名称: getpid
** 功能描述: 获得当前进程号
@@ -766,6 +828,8 @@ int daemon (int nochdir, int noclose)
** 调用模块:
API 函数
*********************************************************************************************************/
+#else /* NO MODULELOADER */
+
LW_API
pid_t getpid (void)
{
diff --git a/SylixOS/posix/include/px_pthread.h b/SylixOS/posix/include/px_pthread.h
index bbf2a4b..c337df6 100644
--- a/SylixOS/posix/include/px_pthread.h
+++ b/SylixOS/posix/include/px_pthread.h
@@ -169,7 +169,7 @@ LW_API int pthread_attr_destroy(pthread_attr_t *pattr);
LW_API int pthread_attr_setstack(pthread_attr_t *pattr, void *pvStackAddr, size_t stSize);
LW_API int pthread_attr_getstack(const pthread_attr_t *pattr, void **ppvStackAddr, size_t *pstSize);
LW_API int pthread_attr_setguardsize(pthread_attr_t *pattr, size_t stGuard);
-LW_API int pthread_attr_getguardsize(pthread_attr_t *pattr, size_t *pstGuard);
+LW_API int pthread_attr_getguardsize(const pthread_attr_t *pattr, size_t *pstGuard);
LW_API int pthread_attr_setstacksize(pthread_attr_t *pattr, size_t stSize);
LW_API int pthread_attr_getstacksize(const pthread_attr_t *pattr, size_t *pstSize);
LW_API int pthread_attr_setstackaddr(pthread_attr_t *pattr, void *pvStackAddr);
@@ -190,6 +190,8 @@ LW_API int pthread_attr_setname(pthread_attr_t *pattr, const char *pc
LW_API int pthread_attr_getname(const pthread_attr_t *pattr, char **ppcName);
#if LW_CFG_POSIXEX_EN > 0
+LW_API int pthread_attr_setinitonly_np(pthread_attr_t *pattr, int init);
+LW_API int pthread_attr_getinitonly_np(const pthread_attr_t *pattr, int *pinit);
LW_API int pthread_attr_get_np(pthread_t thread, pthread_attr_t *pattr);
LW_API int pthread_getattr_np(pthread_t thread, pthread_attr_t *pattr);
LW_API int pthread_setname_np(pthread_t thread, const char *name);
diff --git a/SylixOS/posix/include/px_pthread_np.h b/SylixOS/posix/include/px_pthread_np.h
index cf8f19b..2f7313c 100644
--- a/SylixOS/posix/include/px_pthread_np.h
+++ b/SylixOS/posix/include/px_pthread_np.h
@@ -43,6 +43,7 @@ extern "C" {
LW_API int pthread_null_attr_method_np(int method, int *old_method);
+LW_API int pthread_start_np(pthread_t thread);
LW_API int pthread_wakeup_np(pthread_t thread, int timeout_only);
LW_API int pthread_attr_get_np(pthread_t thread, pthread_attr_t *pattr);
diff --git a/SylixOS/posix/pthread/pthread.c b/SylixOS/posix/pthread/pthread.c
index 6e38619..0f1e7e3 100644
--- a/SylixOS/posix/pthread/pthread.c
+++ b/SylixOS/posix/pthread/pthread.c
@@ -181,11 +181,45 @@ int pthread_create (pthread_t *pthread,
*pthread = ulId; /* 保存线程句柄 */
}
- API_ThreadStart(ulId);
+ if (!(lwattr.THREADATTR_ulOption & LW_OPTION_THREAD_INIT)) {
+ API_ThreadStart(ulId);
+ }
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: pthread_start_np
+** 功能描述: 启动一个已经被初始化的 posix 线程.
+** 输 入 : thread 线程 id.
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_POSIXEX_EN > 0
+
+LW_API
+int pthread_start_np (pthread_t thread)
+{
+ ULONG ulError;
+
+ PX_ID_VERIFY(thread, pthread_t);
+
+ ulError = API_ThreadStart(thread);
+ switch (ulError) {
+
+ case ERROR_KERNEL_HANDLE_NULL:
+ case ERROR_THREAD_NULL:
+ errno = ESRCH;
+ return (ESRCH);
+
+ default:
+ return ((int)ulError);
+ }
+}
+
+#endif /* LW_CFG_POSIXEX_EN > 0 */
+/*********************************************************************************************************
** 函数名称: pthread_cancel
** 功能描述: cancel 一个 posix 线程.
** 输 入 : thread 线程 id.
diff --git a/SylixOS/posix/pthread/pthread_attr.c b/SylixOS/posix/pthread/pthread_attr.c
index d96e9a3..3476012 100644
--- a/SylixOS/posix/pthread/pthread_attr.c
+++ b/SylixOS/posix/pthread/pthread_attr.c
@@ -176,7 +176,7 @@ int pthread_attr_setguardsize (pthread_attr_t *pattr, size_t stGuard)
API 函数
*********************************************************************************************************/
LW_API
-int pthread_attr_getguardsize (pthread_attr_t *pattr, size_t *pstGuard)
+int pthread_attr_getguardsize (const pthread_attr_t *pattr, size_t *pstGuard)
{
if ((pattr == LW_NULL) || (pstGuard == LW_NULL)) {
errno = EINVAL;
@@ -593,6 +593,63 @@ int pthread_attr_getname (const pthread_attr_t *pattr, char **ppcName)
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: pthread_attr_setinitonly_np
+** 功能描述: 设置一个线程属性块是否仅初始化线程.
+** 输 入 : pattr 需要设置的 attr 指针.
+** init 是否仅初始化线程
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_POSIXEX_EN > 0
+
+LW_API
+int pthread_attr_setinitonly_np (pthread_attr_t *pattr, int init)
+{
+ if (pattr == LW_NULL) {
+ errno = EINVAL;
+ return (EINVAL);
+ }
+
+ if (init) {
+ pattr->PTHREADATTR_ulOption |= LW_OPTION_THREAD_INIT;
+ } else {
+ pattr->PTHREADATTR_ulOption &= ~LW_OPTION_THREAD_INIT;
+ }
+
+ return (ERROR_NONE);
+}
+
+/*********************************************************************************************************
+** 函数名称: pthread_attr_getinitonly_np
+** 功能描述: 获取一个线程属性块是否仅初始化线程.
+** 输 入 : pattr 需要设置的 attr 指针.
+** pinit 是否仅初始化线程
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+int pthread_attr_getinitonly_np (const pthread_attr_t *pattr, int *pinit)
+{
+ if ((pattr == LW_NULL) || !pinit) {
+ errno = EINVAL;
+ return (EINVAL);
+ }
+
+ if (pattr->PTHREADATTR_ulOption & LW_OPTION_THREAD_INIT) {
+ *pinit = 1;
+ } else {
+ *pinit = 0;
+ }
+
+ return (ERROR_NONE);
+}
+
+#endif /* LW_CFG_POSIXEX_EN > 0 */
+/*********************************************************************************************************
** 函数名称: pthread_attr_get_np
** 功能描述: 获取线程属性控制块 (FreeBSD 扩展接口)
** 输 入 : thread 线程 ID
diff --git a/SylixOS/system/signal/signalLib.c b/SylixOS/system/signal/signalLib.c
index 8d633a8..1e010fb 100644
--- a/SylixOS/system/signal/signalLib.c
+++ b/SylixOS/system/signal/signalLib.c
@@ -405,6 +405,10 @@ static VOID __sigMakeReady (PLW_CLASS_TCB ptcb,
return;
}
+ if (ptcb->TCB_usStatus & LW_THREAD_STATUS_INIT) { /* 线程仅被初始化, 则线程就绪 */
+ ptcb->TCB_usStatus &= ~LW_THREAD_STATUS_INIT; /* 去掉 init 标志 */
+ }
+
ppcb = _GetPcb(ptcb); /* 获得优先级控制块 */
if (ptcb->TCB_usStatus & LW_THREAD_STATUS_DELAY) { /* 存在于唤醒队列中 */
__DEL_FROM_WAKEUP_LINE(ptcb); /* 从等待链中删除 */