Use "pngdt" as the base name for png.datatype's include files.
[AROS.git] / test / exec / semtorture.c
blob04c4091aa2e2c143b6ee6282b04790564dd0d87e
1 #include <exec/semaphores.h>
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <utility/hooks.h>
7 #include <proto/exec.h>
8 #include <proto/dos.h>
9 #include <proto/intuition.h>
10 #include <proto/graphics.h>
12 #include <clib/alib_protos.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 /****************************************************************************************/
20 struct IntuitionBase *IntuitionBase;
21 struct GfxBase *GfxBase;
23 static struct Screen *scr;
24 static struct Window *win;
25 static struct Task *task1, *task2, *maintask;
27 static struct SignalSemaphore sem;
29 /****************************************************************************************/
31 static void Cleanup(char *msg)
33 WORD rc;
35 if (msg)
37 printf("semtorture: %s\n",msg);
38 rc = RETURN_WARN;
39 } else {
40 rc = RETURN_OK;
43 Forbid();
44 if (task1) DeleteTask(task1);
45 if (task2) DeleteTask(task2);
46 Permit();
48 if (win) CloseWindow(win);
49 if (scr) UnlockPubScreen(0,scr);
51 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
52 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
54 exit(rc);
57 /****************************************************************************************/
59 static void Init(void)
61 InitSemaphore(&sem);
64 /****************************************************************************************/
66 static void OpenLibs(void)
68 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
70 Cleanup("Can't open intuition.library V39!");
73 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
75 Cleanup("Can't open graphics.library V39!");
80 /****************************************************************************************/
82 static void GetVisual(void)
84 if (!(scr = LockPubScreen(0)))
86 Cleanup("Can't lock pub screen!");
90 /****************************************************************************************/
92 static void MakeWin(void)
94 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
95 WA_Left,10,
96 WA_Top,10,
97 WA_Width,300,
98 WA_Height,scr->WBorTop + scr->Font->ta_YSize + 1,
99 WA_Title,(IPTR)"Press RETURN key to start!",
100 WA_SimpleRefresh,TRUE,
101 WA_CloseGadget,TRUE,
102 WA_DepthGadget,TRUE,
103 WA_DragBar,TRUE,
104 WA_Activate,TRUE,
105 WA_IDCMP,IDCMP_CLOSEWINDOW |
106 IDCMP_VANILLAKEY |
107 IDCMP_REFRESHWINDOW,
108 TAG_DONE)))
110 Cleanup("Can't open window!");
113 ScreenToFront(win->WScreen);
117 /****************************************************************************************/
119 static void Task1(void)
121 int a = 1, b = 2, c = 3;
123 for(;;)
125 ObtainSemaphore(&sem);
126 a += b + c;
127 b += a + c;
128 c += a + b;
129 ReleaseSemaphore(&sem);
133 /****************************************************************************************/
135 static void Task2(void)
137 int a = 1, b = 2;
139 for(;;)
141 ObtainSemaphore(&sem);
142 a -= b;
143 b += a;
144 ReleaseSemaphore(&sem);
148 /****************************************************************************************/
150 static void MakeTasks(void)
152 maintask = FindTask(NULL);
154 task1 = CreateTask("Task 1", 0, Task1, 40000);
155 task2 = CreateTask("Task 2", 0, Task2, 40000);
157 if (!task1 || !task2) Cleanup("Can't create tasks!");
161 /****************************************************************************************/
163 static void Action(void)
165 SetWindowTitles(win, "Test started! Cannot be aborted!", (STRPTR)~0);
166 Delay(50);
167 MakeTasks();
170 /****************************************************************************************/
172 static void HandleAll(void)
174 struct IntuiMessage *msg;
176 BOOL quitme = FALSE;
178 while(!quitme)
180 WaitPort(win->UserPort);
181 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
183 switch(msg->Class)
185 case IDCMP_CLOSEWINDOW:
186 quitme = TRUE;
187 break;
189 case IDCMP_REFRESHWINDOW:
190 BeginRefresh(win);
191 EndRefresh(win,TRUE);
192 break;
194 case IDCMP_VANILLAKEY:
195 if (msg->Code == 13) Action();
196 break;
199 ReplyMsg((struct Message *)msg);
204 /****************************************************************************************/
206 int main(void)
208 Init();
209 OpenLibs();
210 GetVisual();
211 MakeWin();
212 HandleAll();
213 Cleanup(0);
214 return 0;
217 /****************************************************************************************/
218 /****************************************************************************************/
219 /****************************************************************************************/
220 /****************************************************************************************/