add flag for spinning tasks
[AROS.git] / compiler / include / exec / tasks.h
blob694cb4f1a2ebcb1846cfa8b78eb70fc70f2cd7d7
1 #ifndef EXEC_TASKS_H
2 #define EXEC_TASKS_H
4 /*
5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: Task structure and constants
9 Lang: english
12 #ifndef EXEC_NODES_H
13 # include <exec/nodes.h>
14 #endif
15 #ifndef EXEC_LISTS_H
16 # include <exec/lists.h>
17 #endif
18 #ifndef EXEC_PORTS_H
19 # include <exec/ports.h>
20 #endif
21 #ifndef UTILITY_TAGITEM_H
22 # include <utility/tagitem.h>
23 #endif
25 struct ETask;
27 /* You must use Exec functions to modify task structure fields. */
28 struct Task
30 struct Node tc_Node;
31 UBYTE tc_Flags;
32 UBYTE tc_State;
33 BYTE tc_IDNestCnt; /* Interrupt disabled nesting */
34 BYTE tc_TDNestCnt; /* Task disabled nesting */
35 ULONG tc_SigAlloc; /* Allocated signals */
36 ULONG tc_SigWait; /* Signals we are waiting for */
37 ULONG tc_SigRecvd; /* Received signals */
38 ULONG tc_SigExcept; /* Signals we will take exceptions for */
39 union
41 struct
43 UWORD tc_ETrapAlloc; /* Allocated traps */
44 UWORD tc_ETrapAble; /* Enabled traps */
45 } tc_ETrap;
46 struct ETask *tc_ETask; /* Valid if TF_ETASK is set */
47 } tc_UnionETask;
48 APTR tc_ExceptData; /* Exception data */
49 APTR tc_ExceptCode; /* Exception code */
50 APTR tc_TrapData; /* Trap data */
51 APTR tc_TrapCode; /* Trap code */
52 APTR tc_SPReg; /* Stack pointer */
53 APTR tc_SPLower; /* Stack lower bound */
54 APTR tc_SPUpper; /* Stack upper bound */
55 VOID (* tc_Switch)(); /* Task loses CPU */
56 VOID (* tc_Launch)(); /* Task gets CPU */
57 struct List tc_MemEntry; /* Allocated memory. Freed by RemTask(). */
58 APTR tc_UserData; /* For use by the task; no restrictions! */
61 #define tc_TrapAlloc tc_UnionETask.tc_ETrap.tc_ETrapAlloc
62 #define tc_TrapAble tc_UnionETask.tc_ETrap.tc_ETrapAble
64 /* Macros */
65 #define GetTrapAlloc(t) \
66 ({struct Task *_t = (struct Task *)t;\
67 (_t->tc_Flags & TF_ETASK) ? _t->tc_UnionETask.tc_ETask->et_TrapAlloc : \
68 _t->tc_UnionETask.tc_ETrap.tc_ETrapAlloc; \
70 #define GetTrapAble(t) \
71 ({struct Task *_t = (struct Task *)t;\
72 (_t->tc_Flags & TF_ETASK) ? _t->tc_UnionETask.tc_ETask->et_TrapAble : \
73 _t->tc_UnionETask.tc_ETrap.tc_ETrapAble;\
75 #define GetETask(t) \
76 ({struct Task *_t = (struct Task *)t;\
77 (_t->tc_Flags & TF_ETASK) ? _t->tc_UnionETask.tc_ETask : NULL; \
79 #define GetETaskID(t) \
80 ({struct Task *_t = (struct Task *)t;\
81 (_t->tc_Flags & TF_ETASK) ? _t->tc_UnionETask.tc_ETask->et_UniqueID: 0UL; \
85 /* Stack swap structure as passed to StackSwap() */
86 struct StackSwapStruct
88 APTR stk_Lower; /* Lowest byte of stack */
89 APTR stk_Upper; /* Upper end of stack (size + Lowest) */
90 APTR stk_Pointer; /* Stack pointer at switch point */
93 struct StackSwapArgs
95 IPTR Args[8]; /* The C function arguments */
98 /* tc_Flags Bits */
99 #define TB_PROCTIME 0
100 #define TB_ETASK 3
101 #define TB_STACKCHK 4
102 #define TB_EXCEPT 5
103 #define TB_SWITCH 6
104 #define TB_LAUNCH 7
106 #define TF_PROCTIME (1L<<0)
107 #define TF_ETASK (1L<<3)
108 #define TF_STACKCHK (1L<<4)
109 #define TF_EXCEPT (1L<<5)
110 #define TF_SWITCH (1L<<6)
111 #define TF_LAUNCH (1L<<7)
113 /* Task States (tc_State) */
114 #define TS_INVALID 0
115 #define TS_ADDED 1
116 #define TS_RUN 2
117 #define TS_READY 3
118 #define TS_WAIT 4
119 #define TS_EXCEPT 5
120 #define TS_REMOVED 6
121 #define TS_SPIN 7 /* AROS specific */
123 /* Predefined Signals */
124 #define SIGB_ABORT 0
125 #define SIGB_CHILD 1
126 #define SIGB_BLIT 4 /* Note: same as SIGB_SINGLE */
127 #define SIGB_SINGLE 4 /* Note: same as SIGB_BLIT */
128 #define SIGB_INTUITION 5
129 #define SIGB_NET 7
130 #define SIGB_DOS 8
132 #define SIGF_ABORT (1L<<0)
133 #define SIGF_CHILD (1L<<1)
134 #define SIGF_BLIT (1L<<4)
135 #define SIGF_SINGLE (1L<<4)
136 #define SIGF_INTUITION (1L<<5)
137 #define SIGF_NET (1L<<7)
138 #define SIGF_DOS (1L<<8)
140 /* Define this when compiling MorphOS-compatible source */
141 #ifdef AROS_MORPHOS_COMPATIBLE
143 #define tc_ETask tc_UnionETask.tc_ETask
145 struct ETask
147 struct Message Message;
148 struct Task *Parent; /* Pointer to task */
149 ULONG UniqueID;
150 struct MinList Children; /* List of children */
151 UWORD TrapAlloc;
152 UWORD TrapAble;
153 ULONG Result1; /* First result */
154 APTR Result2; /* Result data pointer (AllocVec) */
155 struct MsgPort MsgPort;
156 void *MemPool;
157 void *Reserved[2];
158 void *RegFrame;
160 /* Internal fields follow */
163 #else
165 /* Extended Task structure */
166 struct ETask
168 struct Message et_Message;
169 APTR et_Parent; /* Pointer to parent task */
170 ULONG et_UniqueID;
171 struct MinList et_Children; /* List of children */
172 UWORD et_TrapAlloc;
173 UWORD et_TrapAble;
174 ULONG et_Result1; /* First result */
175 APTR et_Result2; /* Result data pointer (AllocVec) */
176 struct MsgPort et_TaskMsgPort;
177 void *et_MemPool; /* Task's private memory pool */
178 #ifdef __AROS__
179 IPTR et_Reserved[1]; /* MorphOS Private */
180 IPTR *et_TaskStorage; /* Task Storage Slots */
181 #else
182 IPTR et_Reserved[2]; /* MorphOS Private */
183 #endif
184 void *et_RegFrame;
185 /* Internal fields follow */
188 #endif
190 /* Return codes from new child functions */
191 #define CHILD_NOTNEW 1 /* Function not called from a new style task */
192 #define CHILD_NOTFOUND 2 /* Child not found */
193 #define CHILD_EXITED 3 /* Child has exited */
194 #define CHILD_ACTIVE 4 /* Child is currently active and running */
196 /* Tags for NewCreateTaskA() and NewAddTask() */
198 #define TASKTAG_Dummy (TAG_USER + 0x100000)
199 #define TASKTAG_ERROR (TASKTAG_Dummy + 0)
200 #define TASKTAG_CODETYPE (TASKTAG_Dummy + 1)
201 #define TASKTAG_PC (TASKTAG_Dummy + 2)
202 #define TASKTAG_FINALPC (TASKTAG_Dummy + 3)
203 #define TASKTAG_STACKSIZE (TASKTAG_Dummy + 4)
204 #define TASKTAG_NAME (TASKTAG_Dummy + 6)
205 #define TASKTAG_USERDATA (TASKTAG_Dummy + 7)
206 #define TASKTAG_PRI (TASKTAG_Dummy + 8)
207 #define TASKTAG_POOLPUDDLE (TASKTAG_Dummy + 9)
208 #define TASKTAG_POOLTHRESH (TASKTAG_Dummy + 10)
209 #define TASKTAG_ARG1 (TASKTAG_Dummy + 16)
210 #define TASKTAG_ARG2 (TASKTAG_Dummy + 17)
211 #define TASKTAG_ARG3 (TASKTAG_Dummy + 18)
212 #define TASKTAG_ARG4 (TASKTAG_Dummy + 19)
213 #define TASKTAG_ARG5 (TASKTAG_Dummy + 20)
214 #define TASKTAG_ARG6 (TASKTAG_Dummy + 21)
215 #define TASKTAG_ARG7 (TASKTAG_Dummy + 22)
216 #define TASKTAG_ARG8 (TASKTAG_Dummy + 23)
217 #define TASKTAG_STARTUPMSG (TASKTAG_Dummy + 24)
218 #define TASKTAG_TASKMSGPORT (TASKTAG_Dummy + 25)
219 #define TASKTAG_FLAGS (TASKTAG_Dummy + 26)
220 #define TASKTAG_TCBEXTRASIZE (TASKTAG_Dummy + 28)
221 #define TASKTAG_AFFINITY (TASKTAG_Dummy + 29)
223 #define TASKERROR_OK 0
224 #define TASKERROR_NOMEMORY 1
226 /* Actions for ShutdownA() */
228 #define SD_ACTION_POWEROFF 0
229 #define SD_ACTION_COLDREBOOT 1
230 #define SD_ACTION_WARMREBOOT 2
232 #endif /* EXEC_TASKS_H */