summaryrefslogtreecommitdiff
path: root/nuttx/sched/pthread_create.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-03-13 23:03:12 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-03-13 23:03:12 +0000
commit9daf318dc8fbefa6d41c739fa53baa155b31887f (patch)
tree1ce7184d3aeb05c749db13b2cc89da654cee76be /nuttx/sched/pthread_create.c
parentbb1f767de46e1648ffc3f5a903969233b2a0d675 (diff)
downloadpx4-nuttx-9daf318dc8fbefa6d41c739fa53baa155b31887f.tar.gz
px4-nuttx-9daf318dc8fbefa6d41c739fa53baa155b31887f.tar.bz2
px4-nuttx-9daf318dc8fbefa6d41c739fa53baa155b31887f.zip
8052 context switch/interrupt integration; pthread arg setup changed
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@60 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/pthread_create.c')
-rw-r--r--nuttx/sched/pthread_create.c72
1 files changed, 68 insertions, 4 deletions
diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c
index 33fdcf00f..4346a6f65 100644
--- a/nuttx/sched/pthread_create.c
+++ b/nuttx/sched/pthread_create.c
@@ -75,11 +75,74 @@ FAR pthread_attr_t g_default_pthread_attr =
* Private Variables
************************************************************/
+/* This is the name for name-less pthreads */
+
+static const char g_pthreadname[] = "<pthread>";
+
/************************************************************
* Private Functions
************************************************************/
/************************************************************
+ * Name: pthread_argsetup
+ *
+ * Description:
+ * This functions sets up parameters in the Task Control
+ * Block (TCB) in preparation for starting a new thread.
+ *
+ * pthread_argsetup() is called from task_init() and task_start()
+ * to create a new task (with arguments cloned via strdup)
+ * or pthread_create() which has one argument passed by
+ * value (distinguished by the pthread boolean argument).
+ *
+ * Input Parameters:
+ * tcb - Address of the new task's TCB
+ * name - Name of the new task (not used)
+ * argv - A pointer to an array of input parameters.
+ * Up to CONFIG_MAX_TASK_ARG parameters may be
+ * provided. If fewer than CONFIG_MAX_TASK_ARG
+ * parameters are passed, the list should be
+ * terminated with a NULL argv[] value.
+ * If no parameters are required, argv may be NULL.
+ *
+ * Return Value:
+ * OK
+ *
+ ************************************************************/
+
+static void pthread_argsetup(FAR _TCB *tcb, pthread_addr_t arg)
+{
+ int i;
+
+#if CONFIG_TASK_NAME_SIZE > 0
+ /* Copy the pthread name into the TCB */
+
+ strncpy(tcb->name, g_pthreadname, CONFIG_TASK_NAME_SIZE);
+
+ /* Save the name as the first argument in the TCB */
+
+ tcb->argv[0] = tcb->name;
+#else
+ /* Save the name as the first argument in the TCB */
+
+ tcb->argv[0] = (char *)g_pthreadname;
+#endif /* CONFIG_TASK_NAME_SIZE */
+
+ /* For pthreads, args are strictly pass-by-value; that actual
+ * type wrapped by pthread_addr_t is unknown.
+ */
+
+ tcb->argv[1] = (char*)arg;
+
+ /* Nullify the remaining, unused argument storage */
+
+ for (i = 2; i < CONFIG_MAX_TASK_ARGS+1; i++)
+ {
+ tcb->argv[i] = NULL;
+ }
+}
+
+/************************************************************
* Function: pthread_addjoininfo
*
* Description:
@@ -178,7 +241,6 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
FAR _TCB *ptcb;
FAR join_t *pjoin;
STATUS status;
- char *argv[2];
int priority;
#if CONFIG_RR_INTERVAL > 0
int policy;
@@ -280,13 +342,15 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
return ERROR;
}
+ /* Mark this task as a pthread */
+
+ ptcb->flags |= TCB_FLAG_PTHREAD;
+
/* Configure the TCB for a pthread receiving on parameter
* passed by value
*/
- argv[0] = (char *)arg;
- argv[1] = NULL;
- (void)task_argsetup(ptcb, NULL, TRUE, argv);
+ (void)pthread_argsetup(ptcb, arg);
/* Attach the join info to the TCB. */