2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Create a new Amiga task
9 #include <exec/memory.h>
10 #include <exec/execbase.h>
11 #include <proto/exec.h>
17 struct MemEntry nml_ME
[2];
20 static const struct newMemList MemTemplate
=
25 { { MEMF_CLEAR
|MEMF_PUBLIC
}, sizeof(struct Task
) },
31 /*****************************************************************************
34 #include <exec/tasks.h>
35 #include <proto/alib.h>
37 struct Task
* CreateTask (
49 name - Name of the task. The string is not copied. Note that
50 task names' need not be unique.
51 pri - The initial priority of the task (normally 0)
52 initpc - The address of the first instruction of the
53 task. In most cases, this is the address of a
55 stacksize - The size of the stack for the task. Always
56 keep in mind that the size of the stack must include
57 the amount of stack which is needed by the routines
61 A pointer to the new task or NULL on failure.
75 ******************************************************************************/
77 struct Task
* newtask
,
79 struct newMemList nml
;
84 stacksize
= AROS_ALIGN(stacksize
);
85 nml
.nml_ME
[1].me_Length
= stacksize
;
87 if (NewAllocEntry((struct MemList
*)&nml
, &ml
, NULL
))
89 newtask
= ml
->ml_ME
[0].me_Addr
;
91 newtask
->tc_Node
.ln_Type
= NT_TASK
;
92 newtask
->tc_Node
.ln_Pri
= pri
;
93 newtask
->tc_Node
.ln_Name
= name
;
95 newtask
->tc_SPReg
= (APTR
)((ULONG
)ml
->ml_ME
[1].me_Addr
+ stacksize
);
96 newtask
->tc_SPLower
= ml
->ml_ME
[1].me_Addr
;
97 newtask
->tc_SPUpper
= newtask
->tc_SPReg
;
99 NewList (&newtask
->tc_MemEntry
);
100 AddHead (&newtask
->tc_MemEntry
, (struct Node
*)ml
);
102 task2
= (struct Task
*)AddTask (newtask
, initpc
, 0);
104 if (SysBase
->LibNode
.lib_Version
>36 && !task2
)