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

  1. head    1.3;
  2. access;
  3. symbols
  4.     version39-41:1.3;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.3
  10. date    92.07.04.19.08.41;    author mwild;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    92.05.18.11.58.15;    author mwild;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    92.05.14.19.55.40;    author mwild;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @wait for synchronous or asynchrounous packets to arrive
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @change to new ix_sleep format, add wmesg-string
  33. @
  34. text
  35. @/*
  36.  *  This file is part of ixemul.library for the Amiga.
  37.  *  Copyright (C) 1991, 1992  Markus M. Wild
  38.  *
  39.  *  This library is free software; you can redistribute it and/or
  40.  *  modify it under the terms of the GNU Library General Public
  41.  *  License as published by the Free Software Foundation; either
  42.  *  version 2 of the License, or (at your option) any later version.
  43.  *
  44.  *  This library is distributed in the hope that it will be useful,
  45.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  46.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  47.  *  Library General Public License for more details.
  48.  *
  49.  *  You should have received a copy of the GNU Library General Public
  50.  *  License along with this library; if not, write to the Free
  51.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  52.  *
  53.  *  $Id: __wait_packet.c,v 1.2 1992/05/18 11:58:15 mwild Exp $
  54.  *
  55.  *  $Log: __wait_packet.c,v $
  56.  * Revision 1.2  1992/05/18  11:58:15  mwild
  57.  * use dp_Port field, NT_REPLYMSG is not reliable
  58.  *
  59.  * Revision 1.1  1992/05/14  19:55:40  mwild
  60.  * Initial revision
  61.  *
  62.  */
  63.  
  64. #define KERNEL
  65. #include "ixemul.h"
  66. #include <signal.h>
  67.  
  68. #ifdef DEBUG
  69. #define DP(a) kprintf a
  70. #else
  71. #define DP(a)
  72. #endif
  73.  
  74. /* isn't defined when ifdef KERNEL */
  75. void    (*signal())();
  76.  
  77. /* I'm using dp_Port as an indicator whether this packet is
  78.    free. If in use, this field can't be 0. */
  79. #define PACKET_IN_USE(sp) (sp->sp_Pkt.dp_Port)
  80.  
  81. /*
  82.  * ^F is a bail-out, if something really goes weird.. 
  83.  */
  84.  
  85. #define SIGMASK ((1<<u.u_sync_mp->mp_SigBit) | SIGBREAKF_CTRL_F)
  86.  
  87. void
  88. __wait_sync_packet(struct StandardPacket *sp)
  89. {
  90.   struct StandardPacket *prw;
  91.   int omask;
  92.  
  93.   /* this is the synchronous way of dealing with packets that may
  94.    * arrive at a port. */
  95.  
  96.   if (! PACKET_IN_USE (sp)) return;
  97.  
  98.   omask = syscall (SYS_sigsetmask, ~0);
  99.  
  100.   for (;;)
  101.     {
  102.       if (prw = GetPacket(u.u_sync_mp))
  103.         {
  104.       PACKET_IN_USE (prw) = 0;
  105.           if (prw == sp) break;
  106.         }
  107.       else
  108.         {
  109.       unsigned long res;
  110.  
  111.       res = Wait(SIGMASK);
  112.       /* process our bail-out-signal */
  113.       if (res & SIGBREAKF_CTRL_F) break;
  114.     }
  115.     }
  116.   
  117.   syscall (SYS_sigsetmask, omask);
  118. }
  119.  
  120.  
  121. void
  122. __wait_packet(struct StandardPacket *sp)
  123. {
  124.   int rc = 0;
  125.  
  126.   /* have to make sure no interrupt is taken between we test and
  127.    * call ix_sleep(), or ix_sleep() will never be awakend..
  128.    * ix_sleep() calls Wait(), and thus breaks the Disable() */
  129.   while (PACKET_IN_USE (sp))
  130.     {
  131. DP(("__wait_packet - "));
  132.       Disable ();
  133.       if (PACKET_IN_USE (sp))
  134.         rc = ix_sleep (sp, "wait_packet");
  135.       Enable ();
  136.       if (rc < 0)
  137.         /* take any outstanding signals, or ix_sleep will never really sleep.. */
  138.         setrun (FindTask (0));
  139.     }
  140. }
  141.  
  142.  
  143. int mp_interrupt (void) __attribute__ ((interrupt));
  144.  
  145. int
  146. mp_interrupt (void)
  147. {
  148.   register struct MsgPort *_mp asm ("a1");
  149.   register struct MsgPort *mp = _mp;
  150.   register struct StandardPacket *prw;
  151.   
  152.   Disable ();
  153.   while (prw = GetPacket (mp))
  154.     {
  155.       PACKET_IN_USE (prw) = 0;
  156.  
  157.       /* wakeup any processes that might be interested in this packet */
  158.       ix_wakeup (prw);
  159.     }
  160.   Enable ();
  161.  
  162.   return 0;
  163. }
  164. @
  165.  
  166.  
  167. 1.2
  168. log
  169. @use dp_Port field, NT_REPLYMSG is not reliable
  170. @
  171. text
  172. @d19 1
  173. a19 1
  174.  *  $Id: __wait_packet.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  175. d22 3
  176. d100 1
  177. a100 1
  178.         rc = ix_sleep (sp);
  179. @
  180.  
  181.  
  182. 1.1
  183. log
  184. @Initial revision
  185. @
  186. text
  187. @d19 1
  188. a19 1
  189.  *  $Id$
  190. d21 4
  191. a24 1
  192.  *  $Log$
  193. d40 4
  194. d59 2
  195. a60 5
  196.   if (sp->sp_Msg.mn_Node.ln_Type != NT_MESSAGE) return;
  197.  
  198.   /* Have to guarantee, that a packet that we receive with GetPacket()
  199.    * is set to NT_REPLYMSG before we allow interrupts again
  200.    */
  201. d67 1
  202. a67 4
  203.        /* every application on the amiga sets the node-type of
  204.         * a reply-msg to NT_REPLYMSG, but DOS has its exception
  205.         * once again.. */
  206.       prw->sp_Msg.mn_Node.ln_Type = NT_REPLYMSG;
  207. d92 1
  208. a92 1
  209.   while (sp->sp_Msg.mn_Node.ln_Type == NT_MESSAGE)
  210. d96 1
  211. a96 1
  212.       if (sp->sp_Msg.mn_Node.ln_Type == NT_MESSAGE)
  213. d118 2
  214. a119 5
  215.       /* every application on the amiga sets the node-type of
  216.        * a reply-msg to NT_REPLYMSG, but DOS has its exception
  217.        * once again.. */
  218.       prw->sp_Msg.mn_Node.ln_Type = NT_REPLYMSG;
  219.       
  220. @
  221.