window simple/smart refresh config support
[tangerine.git] / test / messagetest.c
blob1640c6d5f52334318e76b666db0f6690ca4f9dac
1 /*
2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <exec/ports.h>
8 #include <exec/io.h>
9 #include <exec/memory.h>
10 #include <exec/tasks.h>
11 #include <clib/exec_protos.h>
12 #include "memory.h"
13 #include <stdio.h>
15 #define STACKSIZE 4096
17 static void entry(void)
19 struct MsgPort *port1,*port2;
20 struct Message *msg;
22 Forbid();
23 port1=FindPort("message test port");
24 Permit();
26 port2=CreateMsgPort();
27 if(port2!=NULL)
29 msg=(struct Message *)CreateIORequest(port2,sizeof(struct Message));
30 if(msg!=NULL)
32 int i;
33 for(i=0;i<10;i++)
35 msg->mn_Node.ln_Name=(char *)i;
36 PutMsg(port1,msg);
37 WaitPort(port2);
38 GetMsg(port2);
40 DeleteIORequest((struct IORequest *)msg);
42 DeleteMsgPort(port2);
45 Signal(port1->mp_SigTask,1<<port1->mp_SigBit);
47 Wait(0);/* Let the parent remove me */
50 int main(int argc, char* argv[])
52 struct MsgPort *port1;
53 struct Task *t;
55 port1=CreateMsgPort();
56 if(port1!=NULL)
58 port1->mp_Node.ln_Name="message test port";
60 Forbid();
61 if(FindPort(port1->mp_Node.ln_Name)==NULL)
63 AddPort(port1);
64 Permit();
66 t=(struct Task *)AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
67 if(t!=NULL)
69 UBYTE *s;
70 s=(UBYTE *)AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR);
71 if(s!=NULL)
73 t->tc_Node.ln_Type=NT_TASK;
74 t->tc_Node.ln_Pri=1;
75 t->tc_Node.ln_Name="new task";
76 t->tc_SPLower=s;
77 t->tc_SPUpper=s+STACKSIZE;
78 #if AROS_STACK_GROWS_DOWNWARDS
79 t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET;
80 #else
81 t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET;
82 #endif
83 NEWLIST(&t->tc_MemEntry);
84 AddTask(t,&entry,NULL);
86 Wait(1<<port1->mp_SigBit);
87 if(port1->mp_MsgList.lh_Head->ln_Succ!=NULL)
89 int i;
90 for(i=0;i<10;i++)
92 struct Message *msg;
94 WaitPort(port1);
95 msg=GetMsg(port1);
96 printf("%d\n",(int)msg->mn_Node.ln_Name);
97 ReplyMsg(msg);
100 Wait(1<<port1->mp_SigBit);
101 RemTask(t);
103 FreeMem(s,STACKSIZE);
105 FreeMem(t,sizeof(struct Task));
107 RemPort(port1);
108 }else
109 Permit();
110 DeleteMsgPort(port1);
112 return 0;