home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-1.LHA / CLISP960530-sr.lha / amiga / jchlib / misc / CreatePort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-09  |  1.3 KB  |  55 lines

  1. /* GCC Library
  2.  * Jörg Höhle, 12-Jun-96
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/ports.h>
  7. #include <exec/memory.h>
  8.  
  9. #define __CONSTLIBBASEDECL__ const /* for GCC inlines */
  10. extern struct ExecBase * const SysBase;
  11. #include <proto/exec.h>
  12. #include <proto/alib.h>    /* for NewList() */
  13.  
  14. void DeletePort(struct MsgPort * port);
  15. void DeletePort(port)
  16. struct MsgPort* port;
  17. {
  18.   if (port != NULL)
  19.     {
  20.       if (port->mp_Node.ln_Name)
  21.     { RemPort(port); }
  22.       if (port->mp_Flags == PA_SIGNAL)
  23.         { FreeSignal(port->mp_SigBit); }
  24.       FreeMem(port,sizeof(struct MsgPort));
  25.     }
  26. }
  27.  
  28. struct MsgPort * CreatePort(UBYTE * name, long priority);
  29. struct MsgPort * CreatePort(name, pri)
  30. UBYTE* name;
  31. long pri;
  32. {
  33.   register struct MsgPort* port;
  34.   if ((port = (struct MsgPort *)AllocMem(sizeof(struct MsgPort),MEMF_PUBLIC | MEMF_CLEAR)) != NULL)
  35.     {
  36.       if ((BYTE)(port->mp_SigBit = AllocSignal(-1L)) >= 0)
  37.         {
  38.           port->mp_Node.ln_Name = name;
  39.           port->mp_Node.ln_Type = NT_MSGPORT;
  40.           port->mp_Node.ln_Pri = pri;
  41.           port->mp_SigTask = FindTask(NULL);
  42.           port->mp_Flags = PA_SIGNAL;
  43.           NewList(&port->mp_MsgList);
  44.           if (name != NULL)
  45.         { AddPort(port); }
  46.         }
  47.       else
  48.         {
  49.           FreeMem(port,sizeof(struct MsgPort));
  50.           port = NULL;
  51.         }
  52.     }
  53.   return port;
  54. }
  55.