Build fix, include deflibdefs.h during dependencies generation.
[AROS.git] / rom / exec / newcreatetaska.c
blobb47b3a8f7a440422bf1ac454bcf19b61c4711966
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a new task, improved version
6 Lang: english
7 */
9 #include <proto/arossupport.h>
10 #include <exec/memory.h>
11 #include <exec/execbase.h>
13 #include <string.h>
15 #include "exec_debug.h"
17 struct newMemList
19 struct Node nml_Node;
20 UWORD nml_NumEntries;
21 struct MemEntry nml_ME[3];
24 static const struct newMemList MemTemplate =
26 { 0, },
29 {{MEMF_CLEAR|MEMF_PUBLIC}, sizeof(struct Task)}, /* Task descriptor itself */
30 {{MEMF_CLEAR }, AROS_STACKSIZE }, /* Task's stack */
31 {{MEMF_CLEAR|MEMF_PUBLIC}, 0 } /* Task name */
36 /*****************************************************************************
38 NAME */
39 #include <exec/tasks.h>
40 #include <proto/exec.h>
42 AROS_LH1(struct Task *, NewCreateTaskA,
44 /* SYNOPSIS */
45 AROS_LHA(struct TagItem *, tags, A0),
47 /* LOCATION */
48 struct ExecBase *, SysBase, 153, Exec)
50 /* FUNCTION
51 Create a new task.
53 INPUTS
54 tags - TagList which may contain the following tags:
56 TASKTAG_ERROR (ULONG *) - a pointer to an optional location for secondary
57 return code. The code itself will be set to
58 TASKERROR_OK on success or TASKERROR_NOMEMORY on
59 failure.
60 TASKTAG_PC (APTR) - Start address of the task's code.
61 TAGKTAG_FINALPC (APTR) - Address of the finalization routine. Defaults to
62 SysBase->TaskExitCode.
63 TASKTAG_STACKSIZE (ULONG) - Size of task's stack. Defaults to CPU-dependent
64 value.
65 TASKTAG_NAME (STRPTR) - A pointer to task name. The name will be copied.
66 TASKTAG_USERDATA (APTR) - Anything. Will be written into tc_UserData.
67 TASKTAG_PRI (BYTE) - Task's priority. Defaults to 0.
68 TASKTAG_ARG1 ...
69 TASKTAG_ARG8 (IPTR) - Arguments (up to 8) which will be passed to task's
70 entry function. The arguments are supplied in
71 C-standard way.
72 TASKTAG_FLAGS (ULONG) - Initial value for tc_Flags.
73 TASKTAG_TCBEXTRASIZE (ULONG) - Value which will be added to sizeof(struct Task)
74 in order to determine final size of task structure.
75 Can be used for appending user data to task structure.
77 RESULT
78 A pointer to the new task or NULL on failure.
80 NOTES
82 EXAMPLE
84 BUGS
85 Value of TASKTAG_FLAGS is actually ignored.
86 There are some more tags which are currently not implemented.
88 SEE ALSO
90 INTERNALS
92 HISTORY
94 ******************************************************************************/
96 AROS_LIBFUNC_INIT
98 struct Task * newtask,
99 * task2;
100 struct newMemList nml = MemTemplate;
101 struct MemList * ml;
102 const struct TagItem *tstate = tags;
103 struct TagItem *tag;
104 ULONG *errPtr = NULL;
105 APTR initpc = NULL;
106 APTR finalpc = SysBase->TaskExitCode;
107 char *taskname = NULL;
108 APTR userdata = NULL;
109 ULONG pri = 0;
110 ULONG flags = 0;
112 while ((tag = LibNextTagItem(&tstate)))
114 switch (tag->ti_Tag)
116 case TASKTAG_ERROR:
117 errPtr = (ULONG *)tag->ti_Data;
118 break;
120 case TASKTAG_PC:
121 initpc = (APTR)tag->ti_Data;
122 break;
124 case TASKTAG_FINALPC:
125 finalpc = (APTR)tag->ti_Data;
126 break;
128 case TASKTAG_STACKSIZE:
129 nml.nml_ME[1].me_Length = AROS_ALIGN(tag->ti_Data);
130 break;
132 case TASKTAG_NAME:
133 taskname = (char *)tag->ti_Data;
134 nml.nml_ME[2].me_Length = strlen(taskname) + 1;
135 break;
137 case TASKTAG_USERDATA:
138 userdata = (APTR)tag->ti_Data;
139 break;
141 case TASKTAG_PRI:
142 pri = tag->ti_Data;
143 break;
145 case TASKTAG_FLAGS:
146 flags = tag->ti_Data;
147 break;
149 case TASKTAG_TCBEXTRASIZE:
150 nml.nml_ME[0].me_Length += tag->ti_Data;
151 break;
155 DADDTASK("NewCreateTaskA: name %s\n", taskname ? taskname : "<NULL>");
157 if (NewAllocEntry((struct MemList *)&nml, &ml, NULL))
159 APTR name = ml->ml_ME[2].me_Addr;
161 if (taskname)
162 strcpy(name, taskname);
164 newtask = ml->ml_ME[0].me_Addr;
166 newtask->tc_Node.ln_Type = NT_TASK;
167 newtask->tc_Node.ln_Pri = pri;
168 newtask->tc_Node.ln_Name = name;
170 /* FIXME: NewAddTask() will reset flags to 0 */
171 newtask->tc_Flags = flags;
172 newtask->tc_UserData = userdata;
174 newtask->tc_SPReg = (APTR)((IPTR)ml->ml_ME[1].me_Addr + nml.nml_ME[1].me_Length);
175 newtask->tc_SPLower = ml->ml_ME[1].me_Addr;
176 newtask->tc_SPUpper = newtask->tc_SPReg;
178 NEWLIST(&newtask->tc_MemEntry);
179 AddHead(&newtask->tc_MemEntry, (struct Node *)ml);
181 /* TASKTAG_ARGx will be processed by PrepareContext() */
182 task2 = NewAddTask (newtask, initpc, finalpc, tags);
184 if (!task2)
186 FreeEntry (ml);
187 newtask = NULL;
190 else
191 newtask=NULL;
193 /* Set secondary error code if requested */
194 if (errPtr)
195 *errPtr = newtask ? TASKERROR_OK : TASKERROR_NOMEMORY;
197 return newtask;
199 AROS_LIBFUNC_EXIT