pthread_create must return a positive errno on failure

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1799 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2009-05-19 19:30:57 +00:00
parent 88efd30570
commit 715984992c
3 changed files with 34 additions and 25 deletions
+19 -11
View File
@@ -109,7 +109,7 @@ static const char g_pthreadname[] = "<pthread>";
* If no parameters are required, argv may be NULL. * If no parameters are required, argv may be NULL.
* *
* Return Value: * Return Value:
* OK * None
* *
****************************************************************************/ ****************************************************************************/
@@ -155,7 +155,7 @@ static void pthread_argsetup(FAR _TCB *tcb, pthread_addr_t arg)
* pjoin * pjoin
* *
* Return Value: * Return Value:
* None or pointer to the found entry. * None
* *
* Assumptions: * Assumptions:
* The caller has provided protection from re-entrancy. * The caller has provided protection from re-entrancy.
@@ -235,6 +235,11 @@ static void pthread_start(void)
* attr * attr
* start_routine * start_routine
* arg * arg
*
* Returned value:
* OK (0) on success; a (non-negated) errno value on failure. The errno
* variable is not set.
*
****************************************************************************/ ****************************************************************************/
int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
@@ -261,16 +266,16 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
ptcb = (FAR _TCB*)kzmalloc(sizeof(_TCB)); ptcb = (FAR _TCB*)kzmalloc(sizeof(_TCB));
if (!ptcb) if (!ptcb)
{ {
*get_errno_ptr() = ENOMEM; return ENOMEM;
return ERROR;
} }
/* Associate file descriptors with the new task */ /* Associate file descriptors with the new task */
if (sched_setuppthreadfiles(ptcb) != OK) status = sched_setuppthreadfiles(ptcb);
if (status != OK)
{ {
sched_releasetcb(ptcb); sched_releasetcb(ptcb);
return ERROR; return status;
} }
/* Share the parent's envionment */ /* Share the parent's envionment */
@@ -283,7 +288,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
if (!pjoin) if (!pjoin)
{ {
sched_releasetcb(ptcb); sched_releasetcb(ptcb);
return ERROR; return ENOMEM;
} }
/* Allocate the stack for the TCB */ /* Allocate the stack for the TCB */
@@ -293,7 +298,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
{ {
sched_releasetcb(ptcb); sched_releasetcb(ptcb);
sched_free(pjoin); sched_free(pjoin);
return ERROR; return ENOMEM;
} }
/* Should we use the priority and scheduler specified in the /* Should we use the priority and scheduler specified in the
@@ -345,7 +350,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
sched_releasetcb(ptcb); sched_releasetcb(ptcb);
sched_free(pjoin); sched_free(pjoin);
return ERROR; return EBUSY;
} }
/* Mark this task as a pthread */ /* Mark this task as a pthread */
@@ -385,7 +390,10 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Initialize the semaphores in the join structure to zero. */ /* Initialize the semaphores in the join structure to zero. */
status = sem_init(&pjoin->data_sem, 0, 0); status = sem_init(&pjoin->data_sem, 0, 0);
if (status == OK) status = sem_init(&pjoin->exit_sem, 0, 0); if (status == OK)
{
status = sem_init(&pjoin->exit_sem, 0, 0);
}
/* Activate the task */ /* Activate the task */
@@ -419,7 +427,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
(void)sem_destroy(&pjoin->exit_sem); (void)sem_destroy(&pjoin->exit_sem);
sched_releasetcb(ptcb); sched_releasetcb(ptcb);
sched_free(pjoin); sched_free(pjoin);
return ERROR; return EIO;
} }
return OK; return OK;
} }
+14 -13
View File
@@ -1,7 +1,7 @@
/************************************************************ /****************************************************************************
* sched_setuppthreadfiles.c * sched_setuppthreadfiles.c
* *
* Copyright (C) 2007 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Neither the name Gregory Nutt nor the names of its contributors may be * 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software * used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@@ -31,11 +31,11 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Included Files * Included Files
************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
@@ -49,15 +49,15 @@
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
/************************************************************ /****************************************************************************
* Private Functions * Private Functions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Public Functions * Public Functions
************************************************************/ ****************************************************************************/
/************************************************************ /****************************************************************************
* Function: sched_setuppthreadfiles * Function: sched_setuppthreadfiles
* *
* Description: * Description:
@@ -68,11 +68,12 @@
* tcb - tcb of the new task. * tcb - tcb of the new task.
* *
* Return Value: * Return Value:
* None * OK (if an error were returned, it would need to be a non-negated
* errno value).
* *
* Assumptions: * Assumptions:
* *
************************************************************/ ****************************************************************************/
int sched_setuppthreadfiles(FAR _TCB *tcb) int sched_setuppthreadfiles(FAR _TCB *tcb)
{ {
+1 -1
View File
@@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* task_activate.c * sched/task_activate.c
* *
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>