spl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _SPL_H_
  30. #define _SPL_H_
  31. #include <cdefs.h>
  32. /*
  33. * Machine-independent interface to interrupt enable/disable.
  34. *
  35. * "spl" stands for "set priority level", and was originally the name of
  36. * a VAX assembler instruction.
  37. *
  38. * The idea is that one can block less important interrupts while
  39. * processing them, but still allow more urgent interrupts to interrupt
  40. * that processing.
  41. *
  42. * Ordinarily there would be a whole bunch of defined interrupt
  43. * priority levels and functions for setting them - spltty(),
  44. * splbio(), etc., etc. But we don't support interrupt priorities in
  45. * OS/161, so there are only three:
  46. *
  47. * spl0() sets IPL to 0, enabling all interrupts.
  48. * splhigh() sets IPL to the highest value, disabling all interrupts.
  49. * splx(s) sets IPL to S, enabling whatever state S represents.
  50. *
  51. * All three return the old interrupt state. Thus, these are commonly used
  52. * as follows:
  53. *
  54. * int s = splhigh();
  55. * [ code ]
  56. * splx(s);
  57. *
  58. * Note that these functions only affect interrupts on the current
  59. * processor.
  60. */
  61. int spl0(void);
  62. int splhigh(void);
  63. int splx(int);
  64. /*
  65. * Integer interrupt priority levels.
  66. */
  67. #define IPL_NONE 0
  68. #define IPL_HIGH 1
  69. /*
  70. * Lower-level functions for explicitly raising and lowering
  71. * particular interrupt levels. These are used by splx() and by the
  72. * spinlock code.
  73. *
  74. * A previous setting of OLDIPL is cancelled and replaced with NEWIPL.
  75. *
  76. * For splraise, NEWIPL > OLDIPL, and for spllower, NEWIPL < OLDIPL.
  77. */
  78. void splraise(int oldipl, int newipl);
  79. void spllower(int oldipl, int newipl);
  80. ////////////////////////////////////////////////////////////
  81. /* Inlining support - for making sure an out-of-line copy gets built */
  82. #ifndef SPL_INLINE
  83. #define SPL_INLINE INLINE
  84. #endif
  85. SPL_INLINE
  86. int
  87. spl0(void)
  88. {
  89. return splx(IPL_NONE);
  90. }
  91. SPL_INLINE
  92. int
  93. splhigh(void)
  94. {
  95. return splx(IPL_HIGH);
  96. }
  97. #endif /* _SPL_H_ */