summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-20 18:22:21 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-03-20 18:22:21 +0000
commitfce497aecaf6826d6fec3cfcb761abeac7fe72bf (patch)
tree6d2f0d4610067c2b0e4c3f831274037c9ceba91a /nuttx/sched
parent3d7ed16eabcbea16723b66df2cd2a7d10ba22474 (diff)
downloadpx4-nuttx-fce497aecaf6826d6fec3cfcb761abeac7fe72bf.tar.gz
px4-nuttx-fce497aecaf6826d6fec3cfcb761abeac7fe72bf.tar.bz2
px4-nuttx-fce497aecaf6826d6fec3cfcb761abeac7fe72bf.zip
Change prototypes of up_create_stack and up_release_stack to include a task type parameter
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5765 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/os_internal.h2
-rw-r--r--nuttx/sched/pthread_create.c8
-rw-r--r--nuttx/sched/sched_releasetcb.c11
-rw-r--r--nuttx/sched/task_create.c16
-rw-r--r--nuttx/sched/task_delete.c2
-rw-r--r--nuttx/sched/task_vfork.c24
6 files changed, 43 insertions, 20 deletions
diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h
index 2aa17fa33..0b7236b28 100644
--- a/nuttx/sched/os_internal.h
+++ b/nuttx/sched/os_internal.h
@@ -290,6 +290,6 @@ int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority);
FAR struct tcb_s *sched_gettcb(pid_t pid);
bool sched_verifytcb(FAR struct tcb_s *tcb);
-int sched_releasetcb(FAR struct tcb_s *tcb);
+int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype);
#endif /* __SCHED_OS_INTERNAL_H */
diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c
index 09f98220b..8c9292cfc 100644
--- a/nuttx/sched/pthread_create.c
+++ b/nuttx/sched/pthread_create.c
@@ -294,7 +294,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Allocate the stack for the TCB */
- ret = up_create_stack((FAR struct tcb_s *)ptcb, attr->stacksize);
+ ret = up_create_stack((FAR struct tcb_s *)ptcb, attr->stacksize,
+ TCB_FLAG_TTYPE_PTHREAD);
if (ret != OK)
{
errcode = ENOMEM;
@@ -308,9 +309,10 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
if (attr->inheritsched == PTHREAD_INHERIT_SCHED)
{
+ struct sched_param param;
+
/* Get the priority for this thread. */
- struct sched_param param;
ret = sched_getparam(0, &param);
if (ret == OK)
{
@@ -448,6 +450,6 @@ errout_with_join:
ptcb->joininfo = NULL;
errout_with_tcb:
- sched_releasetcb((FAR struct tcb_s *)ptcb);
+ sched_releasetcb((FAR struct tcb_s *)ptcb, TCB_FLAG_TTYPE_PTHREAD);
return errcode;
}
diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c
index 071b0b37e..185fd4dcd 100644
--- a/nuttx/sched/sched_releasetcb.c
+++ b/nuttx/sched/sched_releasetcb.c
@@ -83,7 +83,12 @@ static void sched_releasepid(pid_t pid)
* Free all resources contained in a TCB
*
* Parameters:
- * None
+ * tcb - The TCB to be released
+ * ttype - The type of the TCB to be released
+ *
+ * This thread type is normally available in the flags field of the TCB,
+ * however, there are certain error recovery contexts where the TCB my
+ * not be fully initialized when sched_releasetcb is called.
*
* Return Value:
* OK on success; ERROR on failure
@@ -93,7 +98,7 @@ static void sched_releasepid(pid_t pid)
*
************************************************************************/
-int sched_releasetcb(FAR struct tcb_s *tcb)
+int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype)
{
int ret = OK;
int i;
@@ -131,7 +136,7 @@ int sched_releasetcb(FAR struct tcb_s *tcb)
#ifndef CONFIG_CUSTOM_STACK
if (tcb->stack_alloc_ptr)
{
- up_release_stack(tcb);
+ up_release_stack(tcb, ttype);
}
#endif
diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c
index 3db41bf5f..a2221c527 100644
--- a/nuttx/sched/task_create.c
+++ b/nuttx/sched/task_create.c
@@ -99,10 +99,10 @@
****************************************************************************/
#ifndef CONFIG_CUSTOM_STACK
-static int thread_create(const char *name, uint8_t ttype, int priority,
+static int thread_create(FAR const char *name, uint8_t ttype, int priority,
int stack_size, main_t entry, FAR char * const argv[])
#else
-static int thread_create(const char *name, uint8_t ttype, int priority,
+static int thread_create(FAR const char *name, uint8_t ttype, int priority,
main_t entry, FAR char * const argv[])
#endif
{
@@ -146,7 +146,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority,
/* Allocate the stack for the TCB */
#ifndef CONFIG_CUSTOM_STACK
- ret = up_create_stack((FAR struct tcb_s *)tcb, stack_size);
+ ret = up_create_stack((FAR struct tcb_s *)tcb, stack_size, ttype);
if (ret < OK)
{
errcode = -ret;
@@ -198,7 +198,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority,
return pid;
errout_with_tcb:
- sched_releasetcb((FAR struct tcb_s *)tcb);
+ sched_releasetcb((FAR struct tcb_s *)tcb, ttype);
errout:
set_errno(errcode);
@@ -244,10 +244,10 @@ errout:
****************************************************************************/
#ifndef CONFIG_CUSTOM_STACK
-int task_create(const char *name, int priority,
+int task_create(FAR const char *name, int priority,
int stack_size, main_t entry, FAR char * const argv[])
#else
-int task_create(const char *name, int priority,
+int task_create(FAR const char *name, int priority,
main_t entry, FAR char * const argv[])
#endif
{
@@ -275,10 +275,10 @@ int task_create(const char *name, int priority,
****************************************************************************/
#ifndef CONFIG_CUSTOM_STACK
-int kernel_thread(const char *name, int priority,
+int kernel_thread(FAR const char *name, int priority,
int stack_size, main_t entry, FAR char * const argv[])
#else
-int kernel_thread(const char *name, int priority,
+int kernel_thread(FAR const char *name, int priority,
main_t entry, FAR char * const argv[])
#endif
{
diff --git a/nuttx/sched/task_delete.c b/nuttx/sched/task_delete.c
index 4a4e00d35..1f51fc15d 100644
--- a/nuttx/sched/task_delete.c
+++ b/nuttx/sched/task_delete.c
@@ -188,7 +188,7 @@ int task_delete(pid_t pid)
/* Deallocate its TCB */
- sched_releasetcb(dtcb);
+ sched_releasetcb(dtcb, dtcb->flags & TCB_FLAG_TTYPE_MASK);
return ret;
}
diff --git a/nuttx/sched/task_vfork.c b/nuttx/sched/task_vfork.c
index 1f365e916..c552f278a 100644
--- a/nuttx/sched/task_vfork.c
+++ b/nuttx/sched/task_vfork.c
@@ -112,11 +112,27 @@ FAR struct task_tcb_s *task_vforksetup(start_t retaddr)
{
struct tcb_s *parent = (FAR struct tcb_s *)g_readytorun.head;
struct task_tcb_s *child;
+ uint8_t ttype;
int priority;
int ret;
DEBUGASSERT(retaddr);
+ /* Get the type of the fork'ed task (kernel or user) */
+
+ if ((parent->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
+ {
+ /* Fork'ed from a kernel thread */
+
+ ttype = TCB_FLAG_TTYPE_KERNEL;
+ }
+ else
+ {
+ /* Fork'ed from a user task or pthread */
+
+ ttype = TCB_FLAG_TTYPE_TASK;
+ }
+
/* Allocate a TCB for the child task. */
child = (FAR struct task_tcb_s *)kzalloc(sizeof(struct task_tcb_s));
@@ -158,8 +174,7 @@ FAR struct task_tcb_s *task_vforksetup(start_t retaddr)
/* Initialize the task control block. This calls up_initial_state() */
svdbg("Child priority=%d start=%p\n", priority, retaddr);
- ret = task_schedsetup(child, priority, retaddr, parent->entry.main,
- TCB_FLAG_TTYPE_TASK);
+ ret = task_schedsetup(child, priority, retaddr, parent->entry.main, ttype);
if (ret < OK)
{
goto errout_with_tcb;
@@ -169,7 +184,7 @@ FAR struct task_tcb_s *task_vforksetup(start_t retaddr)
return child;
errout_with_tcb:
- sched_releasetcb((FAR struct tcb_s *)child);
+ sched_releasetcb((FAR struct tcb_s *)child, ttype);
set_errno(-ret);
return NULL;
}
@@ -321,7 +336,8 @@ void task_vforkabort(FAR struct task_tcb_s *child, int errcode)
/* Release the TCB */
- sched_releasetcb((FAR struct tcb_s *)child);
+ sched_releasetcb((FAR struct tcb_s *)child,
+ child->cmn.flags & TCB_FLAG_TTYPE_MASK);
set_errno(errcode);
}