sched/pthread: simplify pthread_create() branch logic
remove redundant branch logic Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
parent
e456c88c09
commit
cd169e9b2c
@ -59,8 +59,8 @@ void task_initialize(void);
|
||||
int group_initialize(FAR struct task_tcb_s *tcb, uint8_t ttype);
|
||||
void group_postinitialize(FAR struct task_tcb_s *tcb);
|
||||
#ifndef CONFIG_DISABLE_PTHREAD
|
||||
int group_bind(FAR struct pthread_tcb_s *tcb);
|
||||
int group_join(FAR struct pthread_tcb_s *tcb);
|
||||
void group_bind(FAR struct pthread_tcb_s *tcb);
|
||||
void group_join(FAR struct pthread_tcb_s *tcb);
|
||||
#endif
|
||||
void group_leave(FAR struct tcb_s *tcb);
|
||||
void group_drop(FAR struct task_group_s *group);
|
||||
|
@ -51,9 +51,6 @@
|
||||
* Input Parameters:
|
||||
* 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:
|
||||
* - The parent task from which the group will be inherited is the task at
|
||||
* 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();
|
||||
|
||||
@ -71,7 +68,6 @@ int group_bind(FAR struct pthread_tcb_s *tcb)
|
||||
/* Copy the group reference from the parent to the child */
|
||||
|
||||
tcb->cmn.group = ptcb->group;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -83,9 +79,6 @@ int group_bind(FAR struct pthread_tcb_s *tcb)
|
||||
* Input Parameters:
|
||||
* 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:
|
||||
* - The parent task from which the group will be inherited is the task at
|
||||
* 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;
|
||||
irqstate_t flags;
|
||||
@ -110,8 +103,6 @@ int group_join(FAR struct pthread_tcb_s *tcb)
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
sq_addfirst(&tcb->cmn.member, &group->tg_members);
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#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,
|
||||
pthread_startroutine_t entry, pthread_addr_t arg)
|
||||
{
|
||||
pthread_attr_t default_attr = g_default_pthread_attr;
|
||||
FAR struct pthread_tcb_s *ptcb;
|
||||
struct sched_param param;
|
||||
FAR struct tcb_s *parent;
|
||||
int policy;
|
||||
int errcode;
|
||||
pid_t pid;
|
||||
int ret;
|
||||
bool group_joined = false;
|
||||
pthread_attr_t default_attr = g_default_pthread_attr;
|
||||
|
||||
DEBUGASSERT(trampoline != NULL);
|
||||
|
||||
@ -226,12 +224,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
||||
* group).
|
||||
*/
|
||||
|
||||
ret = group_bind(ptcb);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = ENOMEM;
|
||||
goto errout_with_tcb;
|
||||
}
|
||||
group_bind(ptcb);
|
||||
|
||||
#ifdef CONFIG_ARCH_ADDRENV
|
||||
/* 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 */
|
||||
|
||||
ret = group_join(ptcb);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = ENOMEM;
|
||||
goto errout_with_tcb;
|
||||
}
|
||||
|
||||
group_joined = true;
|
||||
group_join(ptcb);
|
||||
|
||||
/* 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
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
|
||||
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);
|
||||
|
||||
/* 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;
|
||||
*thread = (pthread_t)ptcb->cmn.pid;
|
||||
}
|
||||
|
||||
return ret;
|
||||
sched_unlock();
|
||||
|
||||
return OK;
|
||||
|
||||
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);
|
||||
return errcode;
|
||||
|
Loading…
Reference in New Issue
Block a user