Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. mpspin.c
  5. Abstract:
  6. This module implements the hal high level lock manipulation routines.
  7. Author:
  8. Forrest Foltz (forrestf) 1-Dec-2000
  9. Environment:
  10. Kernel mode only.
  11. Revision History:
  12. --*/
  13. #include "halcmn.h"
  14. //
  15. // On UP machines, the high level lock routines are macros
  16. //
  17. #if !defined(NT_UP)
  18. ULONG
  19. HalpAcquireHighLevelLock (
  20. IN PKSPIN_LOCK SpinLock
  21. )
  22. /*++
  23. Routine Description:
  24. Acquires a spinlock with interrupts disabled.
  25. On a UP system, this routine is replaced with a macro that simply disables
  26. interrupts and returns the state of EFLAGS.
  27. Arguments:
  28. SpinLock - Supplies a pointer to a kernel spin lock.
  29. Return Value:
  30. Returns the state of the EFLAGS register.
  31. --*/
  32. {
  33. ULONG flags;
  34. //
  35. // Remember the state of the processor flags
  36. //
  37. flags = HalpGetProcessorFlags();
  38. while (TRUE) {
  39. //
  40. // Disable interrupts and attempt to take the spinlock, exiting
  41. // the loop if it was available.
  42. //
  43. _disable();
  44. if (KeTryToAcquireSpinLockAtDpcLevel(SpinLock) != FALSE) {
  45. break;
  46. }
  47. //
  48. // The spinlock was not available. Restore the state of the
  49. // interrupt flag and spin, waiting for it to become available.
  50. //
  51. HalpRestoreInterrupts(flags);
  52. while (KeTestSpinLock(SpinLock) == FALSE) {
  53. NOTHING;
  54. }
  55. }
  56. return flags;
  57. }
  58. VOID
  59. HalpReleaseHighLevelLock (
  60. IN PKSPIN_LOCK SpinLock,
  61. IN ULONG Flags
  62. )
  63. /*++
  64. Routine Description:
  65. This function releases a kernel spin lock that was taken by
  66. HalpAcquireHighLevelLock() and lowers to the new irql.
  67. On a UP system, this routine is replaced with a macro that simply
  68. restores interrupts based on the state of Flags.
  69. Arguments:
  70. SpinLock - Supplies a pointer to a kernel spin lock.
  71. Flags - The contents of the EFLAGS register when the
  72. lock was taken.
  73. Return Value:
  74. None.
  75. --*/
  76. {
  77. //
  78. // Interrupts at this point are disabled. Release the spinlock and
  79. // enable interrupts if they were enabled when the lock was taken.
  80. //
  81. KeReleaseSpinLockFromDpcLevel(SpinLock);
  82. HalpRestoreInterrupts(Flags);
  83. }
  84. #endif // NT_UP