Source code of Windows XP (NT5)
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.

116 lines
1.9 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. ULONG
  15. HalpAcquireHighLevelLock (
  16. IN PKSPIN_LOCK SpinLock
  17. )
  18. /*++
  19. Routine Description:
  20. Acquires a spinlock with interrupts disabled.
  21. Arguments:
  22. SpinLock - Supplies a pointer to a kernel spin lock.
  23. Return Value:
  24. Returns the state of the EFLAGS register.
  25. --*/
  26. {
  27. ULONG flags;
  28. //
  29. // Remember the state of the processor flags
  30. //
  31. flags = HalpGetProcessorFlags();
  32. while (TRUE) {
  33. //
  34. // Disable interrupts and attempt to take the spinlock, exiting
  35. // the loop if it was available.
  36. //
  37. _disable();
  38. if (KeTryToAcquireSpinLockAtDpcLevel(SpinLock) != FALSE) {
  39. break;
  40. }
  41. //
  42. // The spinlock was not available. Restore the state of the
  43. // interrupt flag and spin, waiting for it to become available.
  44. //
  45. HalpRestoreInterrupts(flags);
  46. while (KeTestSpinLock(SpinLock) == FALSE) {
  47. NOTHING;
  48. }
  49. }
  50. return flags;
  51. }
  52. VOID
  53. HalpReleaseHighLevelLock (
  54. IN PKSPIN_LOCK SpinLock,
  55. IN ULONG Flags
  56. )
  57. /*++
  58. Routine Description:
  59. This function releases a kernel spin lock that was taken by
  60. HalpAcquireHighLevelLock() and lowers to the new irql.
  61. Arguments:
  62. SpinLock - Supplies a pointer to a kernel spin lock.
  63. Flags - The contents of the EFLAGS register when the
  64. lock was taken.
  65. Return Value:
  66. None.
  67. --*/
  68. {
  69. //
  70. // Interrupts at this point are disabled. Release the spinlock and
  71. // enable interrupts if they were enabled when the lock was taken.
  72. //
  73. KeReleaseSpinLockFromDpcLevel(SpinLock);
  74. HalpRestoreInterrupts(Flags);
  75. }