Re-enabled use of AROS.Boot file due to lack of general enthusiasm for
[tangerine.git] / test / exceptiontest2.c
blob472ea9f0f39bfa742a7e1fec443c5173c3708345
1 /*
2 Copyright © 1995-2007, The AROS Development Team.
3 $Id$
5 Desc: Task exception test adapted from tasktest.
6 Lang: english
7 */
9 #include <proto/alib.h>
10 #include <proto/exec.h>
11 #include <exec/tasks.h>
12 #include <stdio.h>
14 int cnt;
15 int excbit;
16 int sigbit1;
17 int sigbit2;
18 struct Task * parent;
20 #define STACKSIZE 4096
22 static ULONG handler(
23 ULONG signals,
24 APTR data,
25 struct ExecBase * SysBase)
27 printf("exception handler called\n");
28 /* this call of Signal will not call the handler
29 again, because the signals handled are disabled
30 during handler execution, we could even avoid
31 excbit from being restored after handling with:
32 signals ^= 1 << excbit */
33 Signal(parent, 1 << sigbit1);
34 return signals;
37 static void entry(void)
39 sigbit2 = AllocSignal(-1);
40 /* signal the parent task via a task exceptions */
41 Signal(parent, 1 << excbit);
42 if (sigbit2 >= 0)
44 int i;
46 for (i = 0; i < 9; i++)
48 Wait(1 << sigbit2);
49 cnt++;
51 for (i = 0; i < 10000; i++)
52 cnt++;
54 FreeSignal(sigbit2);
57 Wait(0); /* Let the parent remove me */
60 int main(int argc, char* argv[])
62 parent = FindTask(NULL);
64 excbit = AllocSignal(-1);
65 sigbit1 = AllocSignal(-1);
66 if (excbit >= 0 && sigbit1 >= 0)
68 APTR oldexc = parent->tc_ExceptCode;
69 parent->tc_ExceptCode = &handler;
70 /* call handler on excbit */
71 SetExcept(1 << excbit, 1 << excbit);
73 struct Task * t = CreateTask("new task", 1, &entry, STACKSIZE);
74 if (t != NULL)
76 Wait(1 << sigbit1);
77 /* we only want to get exceptioned once not on
78 every new call to Signal, so disable excbit */
79 SetExcept(0, 1 << excbit);
80 if (sigbit2 >= 0)
82 int i;
83 for (i = 0; i < 10; i++)
85 Signal(t, 1 << sigbit2);
86 printf("%d\n", cnt);
89 DeleteTask(t);
92 parent->tc_ExceptCode = oldexc;
93 FreeSignal(excbit);
94 FreeSignal(sigbit1);
96 return 0;