mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 11:53:34 +08:00
Add framework to support task groups
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5562 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -251,6 +251,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
#if CONFIG_RR_INTERVAL > 0
|
||||
int policy;
|
||||
#endif
|
||||
int errcode;
|
||||
pid_t pid;
|
||||
|
||||
/* If attributes were not supplied, use the default attributes */
|
||||
@@ -268,6 +269,12 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/* Join the parent's task group */
|
||||
|
||||
#ifdef HAVE_TASK_GROUP
|
||||
group_join(ptcb);
|
||||
#endif
|
||||
|
||||
/* Share the address environment of the parent task. NOTE: Only tasks
|
||||
* created throught the nuttx/binfmt loaders may have an address
|
||||
* environment.
|
||||
@@ -277,8 +284,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
ret = up_addrenv_share((FAR const _TCB *)g_readytorun.head, ptcb);
|
||||
if (ret < 0)
|
||||
{
|
||||
sched_releasetcb(ptcb);
|
||||
return -ret;
|
||||
errcode = -ret;
|
||||
goto errout_with_tcb;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -287,8 +294,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
ret = sched_setuppthreadfiles(ptcb);
|
||||
if (ret != OK)
|
||||
{
|
||||
sched_releasetcb(ptcb);
|
||||
return ret;
|
||||
errcode = ret;
|
||||
goto errout_with_tcb;
|
||||
}
|
||||
|
||||
/* Share the parent's envionment */
|
||||
@@ -300,8 +307,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
pjoin = (FAR join_t*)kzalloc(sizeof(join_t));
|
||||
if (!pjoin)
|
||||
{
|
||||
sched_releasetcb(ptcb);
|
||||
return ENOMEM;
|
||||
errcode = ENOMEM;
|
||||
goto errout_with_tcb;
|
||||
}
|
||||
|
||||
/* Allocate the stack for the TCB */
|
||||
@@ -309,9 +316,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
ret = up_create_stack(ptcb, attr->stacksize);
|
||||
if (ret != OK)
|
||||
{
|
||||
sched_releasetcb(ptcb);
|
||||
sched_free(pjoin);
|
||||
return ENOMEM;
|
||||
errcode = ENOMEM;
|
||||
goto errout_with_join;
|
||||
}
|
||||
|
||||
/* Should we use the priority and scheduler specified in the
|
||||
@@ -360,9 +366,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
TCB_FLAG_TTYPE_PTHREAD);
|
||||
if (ret != OK)
|
||||
{
|
||||
sched_releasetcb(ptcb);
|
||||
sched_free(pjoin);
|
||||
return EBUSY;
|
||||
errcode = EBUSY;
|
||||
goto errout_with_join;
|
||||
}
|
||||
|
||||
/* Configure the TCB for a pthread receiving on parameter
|
||||
@@ -440,10 +445,18 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
|
||||
dq_rem((FAR dq_entry_t*)ptcb, (dq_queue_t*)&g_inactivetasks);
|
||||
(void)sem_destroy(&pjoin->data_sem);
|
||||
(void)sem_destroy(&pjoin->exit_sem);
|
||||
sched_releasetcb(ptcb);
|
||||
sched_free(pjoin);
|
||||
ret = EIO;
|
||||
|
||||
errcode = EIO;
|
||||
goto errout_with_join;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
errout_with_join:
|
||||
sched_free(pjoin);
|
||||
ptcb->joininfo = NULL;
|
||||
|
||||
errout_with_tcb:
|
||||
sched_releasetcb(ptcb);
|
||||
return errcode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user