home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / intext.c < prev    next >
C/C++ Source or Header  |  1999-01-02  |  3KB  |  84 lines

  1. /* -*-C-*-
  2.  
  3. $Id: intext.c,v 1.5 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1990-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include "ansidecl.h"
  23. #include "dstack.h"
  24. #include "intext.h"
  25.  
  26. extern void EXFUN (preserve_signal_mask, (void));
  27.  
  28. struct interruptable_extent * current_interruptable_extent;
  29.  
  30. void
  31. DEFUN_VOID (initialize_interruptable_extent)
  32. {
  33.   current_interruptable_extent = 0;
  34. }
  35.  
  36. void
  37. DEFUN_VOID (reset_interruptable_extent)
  38. {
  39.   current_interruptable_extent = 0;
  40. }
  41.  
  42. struct interruptable_extent *
  43. DEFUN_VOID (enter_interruptable_extent)
  44. {
  45.   PTR position = dstack_position;
  46.   struct interruptable_extent * frame;
  47.   /* Inside the interrupt handler, the signal mask will be different.
  48.      Push a winding frame that will restore it to its current value.
  49.      Do this before any other changes so that the other changes are
  50.      undone before the signal mask is restored (possibly causing
  51.      another interrupt).  */
  52.   preserve_signal_mask ();
  53.   frame = (dstack_alloc (sizeof (struct interruptable_extent)));
  54.   (frame -> position) = position;
  55.   (frame -> interrupted) = 0;
  56.   /* Create a dynamic binding frame but don't assign the new frame to
  57.      it until the setjmp has been done. */
  58.   dstack_bind ((¤t_interruptable_extent), current_interruptable_extent);
  59.   return (frame);
  60. }
  61.  
  62. /* It is possible that two signals arriving close together could both
  63.    set `interrupted'.  This does not matter, because the signal
  64.    handlers haven't done anything at this point, and the net effect is
  65.    to cause the second signal handler to do the longjmp, rather than
  66.    the first.  However, the first signal handler never runs, which may
  67.    be a problem for some applications. */
  68.  
  69. int
  70. DEFUN_VOID (enter_interruption_extent)
  71. {
  72.   if ((current_interruptable_extent == 0)
  73.       || (current_interruptable_extent -> interrupted))
  74.     return (0);
  75.   (current_interruptable_extent -> interrupted) = 1;
  76.   return (1);
  77. }
  78.  
  79. void
  80. DEFUN_VOID (exit_interruption_extent)
  81. {
  82.   longjmp ((current_interruptable_extent -> control_point), 1);
  83. }
  84.