home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / __wait_packet.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  3KB  |  103 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  __wait_packet.c,v 1.1.1.1 1994/04/04 04:30:14 amiga Exp
  20.  *
  21.  *  __wait_packet.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:14  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.3  1992/07/04  19:08:41  mwild
  26.  *  change to new ix_sleep format, add wmesg-string
  27.  *
  28.  * Revision 1.2  1992/05/18  11:58:15  mwild
  29.  * use dp_Port field, NT_REPLYMSG is not reliable
  30.  *
  31.  * Revision 1.1  1992/05/14  19:55:40  mwild
  32.  * Initial revision
  33.  *
  34.  */
  35.  
  36. #define _KERNEL
  37. #include "ixemul.h"
  38. #include "kprintf.h"
  39. #include <signal.h>
  40.  
  41.  
  42. /* I'm using dp_Port as an indicator whether this packet is
  43.    free. If in use, this field can't be 0. */
  44. #define PACKET_IN_USE(sp) (sp->sp_Pkt.dp_Port)
  45.  
  46. void
  47. __wait_sync_packet(struct StandardPacket *sp)
  48. {
  49.   struct StandardPacket *prw;
  50.   int omask;
  51.  
  52.   /* this is the synchronous way of dealing with packets that may
  53.    * arrive at a port. */
  54.  
  55.   if (! PACKET_IN_USE (sp)) return;
  56.  
  57.   omask = syscall (SYS_sigsetmask, ~0);
  58.  
  59.   for (;;)
  60.     {
  61.       if ((prw = GetPacket(u.u_sync_mp)))
  62.         {
  63.       PACKET_IN_USE (prw) = 0;
  64.           if (prw == sp) break;
  65.         }
  66.       else
  67.         {
  68.       Wait(1<<u.u_sync_mp->mp_SigBit);
  69.     }
  70.     }
  71.   
  72.   syscall (SYS_sigsetmask, omask);
  73. }
  74.  
  75. void
  76. __wait_select_packet(struct StandardPacket *sp)
  77. {
  78.   struct StandardPacket *prw;
  79.   int omask;
  80.  
  81.   /* this is the synchronous way of dealing with packets that may
  82.    * arrive at a port. */
  83.  
  84.   if (! PACKET_IN_USE (sp)) return;
  85.  
  86.   omask = syscall (SYS_sigsetmask, ~0);
  87.  
  88.   for (;;)
  89.     {
  90.       if ((prw = GetPacket(u.u_select_mp)))
  91.         {
  92.       PACKET_IN_USE (prw) = 0;
  93.           if (prw == sp) break;
  94.         }
  95.       else
  96.         {
  97.       Wait(1<<u.u_select_mp->mp_SigBit);
  98.     }
  99.     }
  100.   
  101.   syscall (SYS_sigsetmask, omask);
  102. }
  103.