1 #include <exec/semaphores.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <utility/hooks.h>
7 #include <proto/exec.h>
9 #include <proto/intuition.h>
10 #include <proto/graphics.h>
12 #include <clib/alib_protos.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
)
37 printf("semtorture: %s\n",msg
);
44 if (task1
) DeleteTask(task1
);
45 if (task2
) DeleteTask(task2
);
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
);
57 /****************************************************************************************/
59 static void Init(void)
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
,
98 WA_Height
,scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1,
99 WA_Title
,(IPTR
)"Press RETURN key to start!",
100 WA_SimpleRefresh
,TRUE
,
105 WA_IDCMP
,IDCMP_CLOSEWINDOW
|
110 Cleanup("Can't open window!");
113 ScreenToFront(win
->WScreen
);
117 /****************************************************************************************/
119 static void Task1(void)
121 int a
= 1, b
= 2, c
= 3;
125 ObtainSemaphore(&sem
);
129 ReleaseSemaphore(&sem
);
133 /****************************************************************************************/
135 static void Task2(void)
141 ObtainSemaphore(&sem
);
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);
170 /****************************************************************************************/
172 static void HandleAll(void)
174 struct IntuiMessage
*msg
;
180 WaitPort(win
->UserPort
);
181 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
185 case IDCMP_CLOSEWINDOW
:
189 case IDCMP_REFRESHWINDOW
:
191 EndRefresh(win
,TRUE
);
194 case IDCMP_VANILLAKEY
:
195 if (msg
->Code
== 13) Action();
199 ReplyMsg((struct Message
*)msg
);
204 /****************************************************************************************/
217 /****************************************************************************************/
218 /****************************************************************************************/
219 /****************************************************************************************/
220 /****************************************************************************************/