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.

113 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. spinlock.c
  5. Abstract:
  6. This module implements the platform specific functions for acquiring
  7. and releasing spin locks.
  8. Author:
  9. David N. Cutler (davec) 12-Jun-2000
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. VOID
  16. KiAcquireSpinLockCheckForFreeze (
  17. IN PKSPIN_LOCK SpinLock,
  18. IN PKTRAP_FRAME TrapFrame,
  19. IN PKEXCEPTION_FRAME ExceptionFrame
  20. )
  21. /*++
  22. Routine Description:
  23. This function acquires a spin lock from while at high priority.
  24. While the lock is not available, a check is made to see if another
  25. processor has requested this processor to freeze execution.
  26. N.B. This function must be called with IRQL at or above DISPATCH
  27. level, or with interrupts disabled.
  28. Arguments:
  29. SpinLock - Supplies a pointer to a spin lock.
  30. TrapFrame - Supplies a pointer to a trap frame.
  31. ExceptionFrame - Supplies a pointer to an exception frame.
  32. Return Value:
  33. None.
  34. --*/
  35. {
  36. #if !defined(NT_UP)
  37. LONG64 NewSummary;
  38. LONG64 OldSummary;
  39. PKPRCB Prcb;
  40. //
  41. // Attempt to acquire the queued spin lock.
  42. //
  43. // If the previous value of the spinlock is NULL, then the lock has
  44. // been acquired. Otherwise wait for lock ownership to be granted
  45. // while checking for a freeze request.
  46. //
  47. do {
  48. if (KxTryToAcquireSpinLock(SpinLock) != FALSE) {
  49. break;
  50. }
  51. Prcb = KeGetCurrentPrcb();
  52. do {
  53. //
  54. // Check for freeze request while waiting for spin lock to
  55. // become free.
  56. //
  57. OldSummary = Prcb->RequestSummary;
  58. if ((OldSummary & IPI_FREEZE) != 0) {
  59. NewSummary = InterlockedCompareExchange64(&Prcb->RequestSummary,
  60. OldSummary & ~IPI_FREEZE,
  61. OldSummary);
  62. if (OldSummary == NewSummary) {
  63. KiFreezeTargetExecution(TrapFrame, ExceptionFrame);
  64. }
  65. }
  66. } while (*(volatile LONG64 *)SpinLock != 0);
  67. } while (TRUE);
  68. #else
  69. UNREFERENCED_PARAMETER(SpinLock);
  70. UNREFERENCED_PARAMETER(TrapFrame);
  71. UNREFERENCED_PARAMETER(ExceptionFrame);
  72. #endif
  73. return;
  74. }