home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MAILBOX.ZIP / MPSIG.H < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-27  |  4.6 KB  |  99 lines

  1. /****************************************************************************/
  2. /* mpsig.h  -- SIGNAL/INTERRUPT CLUSTER (INTERFACE)                */
  3. /* Created:  11/22/87        Release:  0.7        Version:  06/27/87  */
  4. /****************************************************************************
  5. (c) Copyright 1987 by Michael Benjamin Parker           (USA SS# 557-49-4130)
  6.  
  7. All Rights Reserved unless specified in the following include files:
  8. --no include files--
  9.  
  10. DO NOT REMOVE OR ALTER THIS NOTICE AND ITS PROVISIONS.
  11. ****************************************************************************/
  12. /* OVERVIEW:
  13. The signal/interrupt cluster implements signal/interrupt control needed
  14. for processor - independent_hardware syncronization.  This cluster allows
  15. hardware interrupts to be temporarily blocked so a fragment of code can
  16. be executed without interruption (helping achieve automicity).
  17.  
  18. When the processor has blocked interrupts, if an interrupt occurs it
  19. "waits" (is buffered) until the processor unblocks interrupts, and then
  20. interrupts the processor.  However, each interrupt source (or type) is
  21. ``buffered'' only once, so if the processor is blocks too long and a
  22. source interrupts more than once, only one interrupt event is remembered.
  23. In other words, the processor is interrupted at most once for each
  24. interrupt source when it unblocks.
  25.  
  26. Therefore, if the processor blocks too long, interrupts can be lost --
  27. preventing the processor from doing other timely events (like I/O and
  28. task switching) when it needs to.  "Too long" means longer than the
  29. shortest period between interrupts of the fastest interrupt source.
  30.  
  31. In general, interrupts syncronization is for low-level system
  32. programming.  For task-to-task and task-to-I/O syncronization,
  33. higher-level constructs should be used.
  34. ****************************************************************************/
  35. /****************************************************************************/
  36. #ifndef    MPSIG_H
  37. #define    MPSIG_H
  38. /****************************************************************************/
  39. #if (!((defined(unix) && (defined(vax) || defined(ibm032)||defined(ibm370))) \
  40.     || defined(__TURBOC__) || defined(M_I86)))
  41.     Error!  Currently, this code only runs:
  42.         in UNIX C (on the IBM RT or VAX)
  43.         in MS-DOS (in  Turbo C or Microsoft C)
  44. #endif
  45. /****************************************************************************/
  46. /****************************************************************************/
  47. /* DATA INTERFACE:                                */
  48. /****************************************************************************/
  49. typedef    int    MPSIGSTATE;    /* SIGNAL MASK (SIGNALS BLOCKED FROM
  50.                 DELIVERY - BIT IS ON IFF BLOCKED) */
  51. /****************************************************************************/
  52. /* CODE INTERFACE:                                */
  53. /****************************************************************************/
  54. /* MPSIGSTATE    mpsig_state(MPSIGSTATE newstate);
  55.  
  56. SETS THE SIGNAL BLOCKING STATE.  ALL SIGNALS ARE BLOCKED WITH
  57. MPSIG_ALLBLOCKED (~0).  NO SIGNALS ARE BLOCKED WITH MPSIG_NONEBLOCKED (0).
  58. RETURNS THE PREVIOUS SIGNAL STATE. */
  59. /****************************************************************************/
  60. /* void    mpsig_critsect(CODEBLOCK);
  61.  
  62. A MACRO WHICH EVALUATES CODEBLOCK WITHOUT ANY POSSIBLE INTERRUPTION, IE, IT:
  63.     BLOCKS ALL SIGNALS,
  64.     EVALUATES CODEBLOCK, AND
  65.     THEN RESTORES SIGNALS TO THEIR PREVIOUS STATE. */
  66. /****************************************************************************/
  67. /****************************************************************************/
  68. /****************************************************************************/
  69. /* STRUCTURE, EXTERNAL-VARIBLE, AND MACRO DEFINITION:                */
  70. /****************************************************************************/
  71. #include "mpmisc.h"
  72. #ifdef    unix
  73. #include <signal.h>
  74. #else
  75. #include "mpdos.h"
  76. #endif
  77. /****************************************************************************/
  78. #define    MPSIG_ALLBLOCKED    ((MPSIGSTATE)~0)
  79. #define    MPSIG_NONEBLOCKED    ((MPSIGSTATE)0)
  80. #ifndef    unix
  81. #define    mpsig_state(new)            \
  82.     (_FLAG & _FLAG_IF);            \
  83.     (new)?(disable()):(enable())
  84. #else
  85. #define    mpsig_state(new)            \
  86.     sigsetmask(new)
  87. #endif
  88. /****************************************************************************/
  89. #define    mpsig_critsect(CODEBLOCK)                    \
  90.     {                                \
  91.         MPSIGSTATE mpsigstate=    mpsig_state(MPSIG_ALLBLOCKED);    \
  92.         {CODEBLOCK}                        \
  93.                     mpsig_state(mpsigstate);    \
  94.     }
  95. /****************************************************************************/
  96. /****************************************************************************/
  97. /****************************************************************************/
  98. #endif /* MPSIG_H */
  99.