home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / test / messagetest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-24  |  2.7 KB  |  134 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: messagetest.c,v 1.4 1996/10/23 14:07:20 aros Exp $
  4.     $Log: messagetest.c,v $
  5.     Revision 1.4  1996/10/23 14:07:20  aros
  6.     #define was renamed
  7.  
  8.     Revision 1.3  1996/10/19 17:07:32  aros
  9.     Include <aros/machine.h> instead of machine.h
  10.  
  11.     Revision 1.2  1996/08/01 17:41:40  digulla
  12.     Added standard header for all files
  13.  
  14.     Desc:
  15.     Lang:
  16. */
  17. #include <exec/ports.h>
  18. #include <exec/io.h>
  19. #include <exec/memory.h>
  20. #include <exec/tasks.h>
  21. #include <clib/exec_protos.h>
  22. #include "memory.h"
  23. #include <aros/machine.h>
  24. #include <stdio.h>
  25.  
  26. #define NEWLIST(l)                          \
  27. ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
  28.  (l)->lh_Tail=NULL,                         \
  29.  (l)->lh_TailPred=(struct Node *)(l))
  30.  
  31. /* shared */
  32. extern struct ExecBase *SysBase;
  33.  
  34. #define STACKSIZE 4096
  35.  
  36. static void entry(void)
  37. {
  38.     struct MsgPort *port1,*port2;
  39.     struct Message *msg;
  40.  
  41.     Forbid();
  42.     port1=FindPort("message test port");
  43.     Permit();
  44.  
  45.     port2=CreateMsgPort();
  46.     if(port2!=NULL)
  47.     {
  48.     msg=(struct Message *)CreateIORequest(port2,sizeof(struct Message));
  49.     if(msg!=NULL)
  50.     {
  51.         int i;
  52.         for(i=0;i<10;i++)
  53.         {
  54.         msg->mn_Node.ln_Name=(char *)i;
  55.         PutMsg(port1,msg);
  56.         WaitPort(port2);
  57.         GetMsg(port2);
  58.         }
  59.         DeleteIORequest((struct IORequest *)msg);
  60.     }
  61.     DeleteMsgPort(port2);
  62.     }
  63.  
  64.     Signal(port1->mp_SigTask,1<<port1->mp_SigBit);
  65.  
  66.     Wait(0);/* Let the parent remove me */
  67. }
  68.  
  69. int main(int argc, char* argv[])
  70. {
  71.     struct MsgPort *port1;
  72.     struct Task *t;
  73.  
  74.     port1=CreateMsgPort();
  75.     if(port1!=NULL)
  76.     {
  77.     port1->mp_Node.ln_Name="message test port";
  78.  
  79.     Forbid();
  80.     if(FindPort(port1->mp_Node.ln_Name)==NULL)
  81.     {
  82.         AddPort(port1);
  83.         Permit();
  84.  
  85.         t=(struct Task *)AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
  86.         if(t!=NULL)
  87.         {
  88.         UBYTE *s;
  89.         s=(UBYTE *)AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR);
  90.         if(s!=NULL)
  91.         {
  92.             t->tc_Node.ln_Type=NT_TASK;
  93.             t->tc_Node.ln_Pri=1;
  94.             t->tc_Node.ln_Name="new task";
  95.             t->tc_SPLower=s;
  96.             t->tc_SPUpper=s+STACKSIZE;
  97. #if AROS_STACK_GROWS_DOWNWARDS
  98.             t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET;
  99. #else
  100.             t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET;
  101. #endif
  102.             NEWLIST(&t->tc_MemEntry);
  103.             AddTask(t,&entry,NULL);
  104.  
  105.             Wait(1<<port1->mp_SigBit);
  106.             if(port1->mp_MsgList.lh_Head->ln_Succ!=NULL)
  107.             {
  108.             int i;
  109.             for(i=0;i<10;i++)
  110.             {
  111.                 struct Message *msg;
  112.  
  113.                 WaitPort(port1);
  114.                 msg=GetMsg(port1);
  115.                 printf("%d\n",(int)msg->mn_Node.ln_Name);
  116.                 ReplyMsg(msg);
  117.             }
  118.  
  119.             Wait(1<<port1->mp_SigBit);
  120.             RemTask(t);
  121.             }
  122.             FreeMem(s,STACKSIZE);
  123.         }
  124.         FreeMem(t,sizeof(struct Task));
  125.         }
  126.         RemPort(port1);
  127.     }else
  128.         Permit();
  129.     DeleteMsgPort(port1);
  130.     }
  131.     return 0;
  132. }
  133.  
  134.