mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
sched/pthread: simplify pthread_create() branch logic
remove redundant branch logic Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
+2
-2
@@ -59,8 +59,8 @@ void task_initialize(void);
|
|||||||
int group_initialize(FAR struct task_tcb_s *tcb, uint8_t ttype);
|
int group_initialize(FAR struct task_tcb_s *tcb, uint8_t ttype);
|
||||||
void group_postinitialize(FAR struct task_tcb_s *tcb);
|
void group_postinitialize(FAR struct task_tcb_s *tcb);
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
#ifndef CONFIG_DISABLE_PTHREAD
|
||||||
int group_bind(FAR struct pthread_tcb_s *tcb);
|
void group_bind(FAR struct pthread_tcb_s *tcb);
|
||||||
int group_join(FAR struct pthread_tcb_s *tcb);
|
void group_join(FAR struct pthread_tcb_s *tcb);
|
||||||
#endif
|
#endif
|
||||||
void group_leave(FAR struct tcb_s *tcb);
|
void group_leave(FAR struct tcb_s *tcb);
|
||||||
void group_drop(FAR struct task_group_s *group);
|
void group_drop(FAR struct task_group_s *group);
|
||||||
|
|||||||
@@ -51,9 +51,6 @@
|
|||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* tcb - The TCB of the new "child" task that need to join the group.
|
* tcb - The TCB of the new "child" task that need to join the group.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
|
||||||
* 0 (OK) on success; a negated errno value on failure.
|
|
||||||
*
|
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* - The parent task from which the group will be inherited is the task at
|
* - The parent task from which the group will be inherited is the task at
|
||||||
* the head of the ready to run list.
|
* the head of the ready to run list.
|
||||||
@@ -62,7 +59,7 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int group_bind(FAR struct pthread_tcb_s *tcb)
|
void group_bind(FAR struct pthread_tcb_s *tcb)
|
||||||
{
|
{
|
||||||
FAR struct tcb_s *ptcb = this_task();
|
FAR struct tcb_s *ptcb = this_task();
|
||||||
|
|
||||||
@@ -71,7 +68,6 @@ int group_bind(FAR struct pthread_tcb_s *tcb)
|
|||||||
/* Copy the group reference from the parent to the child */
|
/* Copy the group reference from the parent to the child */
|
||||||
|
|
||||||
tcb->cmn.group = ptcb->group;
|
tcb->cmn.group = ptcb->group;
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -83,9 +79,6 @@ int group_bind(FAR struct pthread_tcb_s *tcb)
|
|||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* tcb - The TCB of the new "child" task that need to join the group.
|
* tcb - The TCB of the new "child" task that need to join the group.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
|
||||||
* 0 (OK) on success; a negated errno value on failure.
|
|
||||||
*
|
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
* - The parent task from which the group will be inherited is the task at
|
* - The parent task from which the group will be inherited is the task at
|
||||||
* the head of the ready to run list.
|
* the head of the ready to run list.
|
||||||
@@ -94,7 +87,7 @@ int group_bind(FAR struct pthread_tcb_s *tcb)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int group_join(FAR struct pthread_tcb_s *tcb)
|
void group_join(FAR struct pthread_tcb_s *tcb)
|
||||||
{
|
{
|
||||||
FAR struct task_group_s *group;
|
FAR struct task_group_s *group;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
@@ -110,8 +103,6 @@ int group_join(FAR struct pthread_tcb_s *tcb)
|
|||||||
flags = spin_lock_irqsave(NULL);
|
flags = spin_lock_irqsave(NULL);
|
||||||
sq_addfirst(&tcb->cmn.member, &group->tg_members);
|
sq_addfirst(&tcb->cmn.member, &group->tg_members);
|
||||||
spin_unlock_irqrestore(NULL, flags);
|
spin_unlock_irqrestore(NULL, flags);
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_DISABLE_PTHREAD */
|
#endif /* !CONFIG_DISABLE_PTHREAD */
|
||||||
|
|||||||
@@ -178,15 +178,13 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
|||||||
FAR const pthread_attr_t *attr,
|
FAR const pthread_attr_t *attr,
|
||||||
pthread_startroutine_t entry, pthread_addr_t arg)
|
pthread_startroutine_t entry, pthread_addr_t arg)
|
||||||
{
|
{
|
||||||
|
pthread_attr_t default_attr = g_default_pthread_attr;
|
||||||
FAR struct pthread_tcb_s *ptcb;
|
FAR struct pthread_tcb_s *ptcb;
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
FAR struct tcb_s *parent;
|
FAR struct tcb_s *parent;
|
||||||
int policy;
|
int policy;
|
||||||
int errcode;
|
int errcode;
|
||||||
pid_t pid;
|
|
||||||
int ret;
|
int ret;
|
||||||
bool group_joined = false;
|
|
||||||
pthread_attr_t default_attr = g_default_pthread_attr;
|
|
||||||
|
|
||||||
DEBUGASSERT(trampoline != NULL);
|
DEBUGASSERT(trampoline != NULL);
|
||||||
|
|
||||||
@@ -226,12 +224,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
|||||||
* group).
|
* group).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = group_bind(ptcb);
|
group_bind(ptcb);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
errcode = ENOMEM;
|
|
||||||
goto errout_with_tcb;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_ADDRENV
|
#ifdef CONFIG_ARCH_ADDRENV
|
||||||
/* Share the address environment of the parent task group. */
|
/* Share the address environment of the parent task group. */
|
||||||
@@ -420,14 +413,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
|||||||
|
|
||||||
/* Join the parent's task group */
|
/* Join the parent's task group */
|
||||||
|
|
||||||
ret = group_join(ptcb);
|
group_join(ptcb);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
errcode = ENOMEM;
|
|
||||||
goto errout_with_tcb;
|
|
||||||
}
|
|
||||||
|
|
||||||
group_joined = true;
|
|
||||||
|
|
||||||
/* Set the appropriate scheduling policy in the TCB */
|
/* Set the appropriate scheduling policy in the TCB */
|
||||||
|
|
||||||
@@ -454,47 +440,28 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the assigned pid before we start the task (who knows what
|
|
||||||
* could happen to ptcb after this!).
|
|
||||||
*/
|
|
||||||
|
|
||||||
pid = ptcb->cmn.pid;
|
|
||||||
|
|
||||||
/* Then activate the task */
|
/* Then activate the task */
|
||||||
|
|
||||||
sched_lock();
|
sched_lock();
|
||||||
if (ret == OK)
|
|
||||||
|
nxtask_activate((FAR struct tcb_s *)ptcb);
|
||||||
|
|
||||||
|
/* Return the thread information to the caller */
|
||||||
|
|
||||||
|
if (thread != NULL)
|
||||||
{
|
{
|
||||||
nxtask_activate((FAR struct tcb_s *)ptcb);
|
*thread = (pthread_t)ptcb->cmn.pid;
|
||||||
|
|
||||||
/* Return the thread information to the caller */
|
|
||||||
|
|
||||||
if (thread)
|
|
||||||
{
|
|
||||||
*thread = (pthread_t)pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
sched_unlock();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sched_unlock();
|
|
||||||
dq_rem((FAR dq_entry_t *)ptcb, list_inactivetasks());
|
|
||||||
|
|
||||||
errcode = EIO;
|
|
||||||
goto errout_with_tcb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
sched_unlock();
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
|
||||||
errout_with_tcb:
|
errout_with_tcb:
|
||||||
|
|
||||||
/* Clear group binding */
|
/* Since we do not join the group, assign group to NULL to clear binding */
|
||||||
|
|
||||||
if (ptcb && !group_joined)
|
ptcb->cmn.group = NULL;
|
||||||
{
|
|
||||||
ptcb->cmn.group = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
nxsched_release_tcb((FAR struct tcb_s *)ptcb, TCB_FLAG_TTYPE_PTHREAD);
|
nxsched_release_tcb((FAR struct tcb_s *)ptcb, TCB_FLAG_TTYPE_PTHREAD);
|
||||||
return errcode;
|
return errcode;
|
||||||
|
|||||||
Reference in New Issue
Block a user