home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / createport.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.7 KB  |  127 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @create msgport
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50.  
  51. #include <exec/ports.h>
  52. #include <exec/interrupts.h>
  53.  
  54. struct MsgPort *
  55. CreatePort(const char *name, int pri)
  56. {
  57.   int sigBit;
  58.   struct MsgPort *port;
  59.   
  60.   if ((sigBit = AllocSignal(-1)) == -1) return 0;
  61.   
  62.   port = (struct MsgPort *) kmalloc (sizeof (struct MsgPort));
  63.   if (! port)
  64.     {
  65.       FreeSignal (sigBit);
  66.       errno = ENOMEM;
  67.       return 0;
  68.     }
  69.     
  70.   bzero (port, sizeof (struct MsgPort));
  71.   
  72.   port->mp_Node.ln_Name = name;
  73.   port->mp_Node.ln_Pri = pri;
  74.   port->mp_Node.ln_Type = NT_MSGPORT;
  75.   
  76.   port->mp_Flags = PA_SIGNAL;
  77.   port->mp_SigBit = sigBit;
  78.   port->mp_SigTask = FindTask (0);
  79.   
  80.   if (name)
  81.     AddPort (port);
  82.   else
  83.     NewList (&(port->mp_MsgList));
  84.     
  85.   return port;
  86. }
  87.  
  88. struct MsgPort *
  89. CreateInterruptPort (const char *name, int pri, void (*code)(), void *data)
  90. {
  91.   struct MsgPort *port;
  92.   struct Interrupt *interrupt;
  93.  
  94.   if (port = (struct MsgPort *) kmalloc (sizeof (struct MsgPort)))
  95.     {
  96.       if (interrupt = (struct Interrupt *) kmalloc (sizeof (struct Interrupt)))
  97.         {
  98.       bzero (interrupt, sizeof (struct Interrupt));
  99.           interrupt->is_Node.ln_Type = NT_INTERRUPT;
  100.       /* as a convenience, if data is 0, set it to the port itself */
  101.           interrupt->is_Data = data ? data : port;
  102.           interrupt->is_Code = code;
  103.           
  104.           bzero (port, sizeof (struct MsgPort));
  105.       port->mp_Node.ln_Name = name;
  106.       port->mp_Node.ln_Pri = pri;
  107.       port->mp_Node.ln_Type = NT_MSGPORT;
  108.           
  109.       port->mp_Flags = PA_SOFTINT;
  110.       port->mp_SoftInt = interrupt;
  111.  
  112.       if (name)
  113.         AddPort (port);
  114.       else
  115.         NewList (&(port->mp_MsgList));
  116.     
  117.       return port;
  118.     }
  119.       
  120.       kfree (port);
  121.     }
  122.  
  123.   errno = ENOMEM;
  124.   return 0;
  125. }
  126. @
  127.