tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / test / exec / semtorture.c
blobb14e8192f357012c0b50988e2368b881bc1f7d4d
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/semaphores.h>
7 #include <dos/dos.h>
8 #include <intuition/intuition.h>
9 #include <graphics/gfx.h>
10 #include <utility/hooks.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/intuition.h>
15 #include <proto/graphics.h>
17 #include <clib/alib_protos.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
23 /****************************************************************************************/
25 struct IntuitionBase *IntuitionBase;
26 struct GfxBase *GfxBase;
28 static struct Screen *scr;
29 static struct Window *win;
30 static struct Task *task1, *task2, *maintask;
32 static struct SignalSemaphore sem;
34 /****************************************************************************************/
36 static void Cleanup(char *msg)
38 WORD rc;
40 if (msg)
42 printf("semtorture: %s\n",msg);
43 rc = RETURN_WARN;
44 } else {
45 rc = RETURN_OK;
48 Forbid();
49 if (task1) DeleteTask(task1);
50 if (task2) DeleteTask(task2);
51 Permit();
53 if (win) CloseWindow(win);
54 if (scr) UnlockPubScreen(0,scr);
56 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
57 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
59 exit(rc);
62 /****************************************************************************************/
64 static void Init(void)
66 InitSemaphore(&sem);
69 /****************************************************************************************/
71 static void OpenLibs(void)
73 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
75 Cleanup("Can't open intuition.library V39!");
78 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
80 Cleanup("Can't open graphics.library V39!");
85 /****************************************************************************************/
87 static void GetVisual(void)
89 if (!(scr = LockPubScreen(0)))
91 Cleanup("Can't lock pub screen!");
95 /****************************************************************************************/
97 static void MakeWin(void)
99 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
100 WA_Left,10,
101 WA_Top,10,
102 WA_Width,300,
103 WA_Height,scr->WBorTop + scr->Font->ta_YSize + 1,
104 WA_Title,(IPTR)"Press RETURN key to start!",
105 WA_SimpleRefresh,TRUE,
106 WA_CloseGadget,TRUE,
107 WA_DepthGadget,TRUE,
108 WA_DragBar,TRUE,
109 WA_Activate,TRUE,
110 WA_IDCMP,IDCMP_CLOSEWINDOW |
111 IDCMP_VANILLAKEY |
112 IDCMP_REFRESHWINDOW,
113 TAG_DONE)))
115 Cleanup("Can't open window!");
118 ScreenToFront(win->WScreen);
122 /****************************************************************************************/
124 static void Task1(void)
126 int a = 1, b = 2, c = 3;
128 for(;;)
130 ObtainSemaphore(&sem);
131 a += b + c;
132 b += a + c;
133 c += a + b;
134 ReleaseSemaphore(&sem);
138 /****************************************************************************************/
140 static void Task2(void)
142 int a = 1, b = 2;
144 for(;;)
146 ObtainSemaphore(&sem);
147 a -= b;
148 b += a;
149 ReleaseSemaphore(&sem);
153 /****************************************************************************************/
155 static void MakeTasks(void)
157 maintask = FindTask(NULL);
159 task1 = CreateTask("Task 1", 0, Task1, 40000);
160 task2 = CreateTask("Task 2", 0, Task2, 40000);
162 if (!task1 || !task2) Cleanup("Can't create tasks!");
166 /****************************************************************************************/
168 static void Action(void)
170 SetWindowTitles(win, "Test started! Cannot be aborted!", (STRPTR)~0);
171 Delay(50);
172 MakeTasks();
175 /****************************************************************************************/
177 static void HandleAll(void)
179 struct IntuiMessage *msg;
181 BOOL quitme = FALSE;
183 while(!quitme)
185 WaitPort(win->UserPort);
186 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
188 switch(msg->Class)
190 case IDCMP_CLOSEWINDOW:
191 quitme = TRUE;
192 break;
194 case IDCMP_REFRESHWINDOW:
195 BeginRefresh(win);
196 EndRefresh(win,TRUE);
197 break;
199 case IDCMP_VANILLAKEY:
200 if (msg->Code == 13) Action();
201 break;
204 ReplyMsg((struct Message *)msg);
209 /****************************************************************************************/
211 int main(void)
213 Init();
214 OpenLibs();
215 GetVisual();
216 MakeWin();
217 HandleAll();
218 Cleanup(0);
219 return 0;
222 /****************************************************************************************/
223 /****************************************************************************************/
224 /****************************************************************************************/
225 /****************************************************************************************/