Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / compiler / alib / createtask.c
blobf320ee06bb850058dca09e61d3b52004914d26dc
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a new Amiga task
6 Lang: english
7 */
9 #include <exec/memory.h>
10 #include <exec/execbase.h>
11 #include <proto/exec.h>
13 struct newMemList
15 struct Node nml_Node;
16 UWORD nml_NumEntries;
17 struct MemEntry nml_ME[2];
20 static const struct newMemList MemTemplate =
22 { 0, },
25 { { MEMF_CLEAR|MEMF_PUBLIC }, sizeof(struct Task) },
26 { { MEMF_CLEAR }, 0 }
31 /*****************************************************************************
33 NAME */
34 #include <exec/tasks.h>
35 #include <proto/alib.h>
37 struct Task * CreateTask (
39 /* SYNOPSIS */
40 STRPTR name,
41 LONG pri,
42 APTR initpc,
43 ULONG stacksize)
45 /* FUNCTION
46 Create a new task.
48 INPUTS
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
54 function.
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
58 called by the task.
60 RESULT
61 A pointer to the new task or NULL on failure.
63 NOTES
65 EXAMPLE
67 BUGS
69 SEE ALSO
71 INTERNALS
73 HISTORY
75 ******************************************************************************/
77 struct Task * newtask,
78 * task2;
79 struct newMemList nml;
80 struct MemList * ml;
82 nml = MemTemplate;
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)
106 FreeEntry (ml);
107 newtask = NULL;
110 else
111 newtask=NULL;
113 return newtask;
114 } /* CreateTask */