squashed commit of private hostlib-resource branch
[tangerine.git] / test / tasktest2.c
blobe3640b42570349bbdd6ef1cd24060f72622ad7f5
1 /*
2 Copyright © 1995-2002, The AROS Development Team.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <exec/execbase.h>
8 #include <exec/memory.h>
9 #include <exec/tasks.h>
10 #include <clib/exec_protos.h>
11 #include "memory.h"
12 #include <stdio.h>
14 int cnt;
15 int sigbit1,sigbit2;
16 struct Task *parent;
18 #define STACKSIZE 4096
20 static void entry(void)
22 int i=0;
24 sigbit2=AllocSignal(-1);
25 Signal(parent,1<<sigbit1);
26 if(sigbit2>=0)
28 for(i=0;i<9;i++)
30 Wait(1<<sigbit2);
31 cnt++;
33 for(i=0;i<10000;i++)
34 cnt++;
36 FreeSignal(sigbit2);
38 Wait(0);/* Let the parent remove me */
41 int main(int argc, char* argv[])
43 struct Task *t;
45 parent=SysBase->ThisTask;
47 sigbit1=AllocSignal(-1);
48 if(sigbit1>=0)
50 t=(struct Task *)AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
51 if(t!=NULL)
53 UBYTE *s;
54 s=(UBYTE *)AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR);
55 if(s!=NULL)
57 t->tc_Node.ln_Type=NT_TASK;
58 t->tc_Node.ln_Pri=0;
59 t->tc_Node.ln_Name="new task";
60 t->tc_SPLower=s;
61 t->tc_SPUpper=s+STACKSIZE;
62 #if AROS_STACK_GROWS_DOWNWARDS
63 t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET;
64 #else
65 t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET;
66 #endif
67 NEWLIST(&t->tc_MemEntry);
68 AddTask(t,&entry,NULL);
69 SetTaskPri(t,1);
70 printf("%p %p %p %p\n",t,FindTask("new task"),
71 SysBase->ThisTask,FindTask(NULL));
72 Wait(1<<sigbit1);
73 if(sigbit2>=0)
75 int i;
76 for(i=0;i<10;i++)
78 Signal(t,1<<sigbit2);
79 printf("%d\n",cnt);
81 RemTask(t);
83 FreeMem(s,STACKSIZE);
85 FreeMem(t,sizeof(struct Task));
87 FreeSignal(sigbit1);
89 return 0;