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.

117 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. intrloc2.c
  5. Abstract:
  6. This module implements the *portable* (i.e. SLOW) versions of
  7. the executive's simple atomic increment/decrement procedures.
  8. Real implementation should be in assembler.
  9. Author:
  10. Bryan Willman (bryanwi) 2-Aug-90
  11. Environment:
  12. Kernel mode only.
  13. Revision History:
  14. --*/
  15. #include "exp.h"
  16. INTERLOCKED_RESULT
  17. ExInterlockedIncrementLong (
  18. IN PLONG Addend,
  19. IN PKSPIN_LOCK Lock
  20. )
  21. /*++
  22. Routine Description:
  23. This function atomically increments Addend, returning an ennumerated
  24. type which indicates what interesting transitions in the value of
  25. Addend occurred due the operation.
  26. Arguments:
  27. Addend - Pointer to variable to increment.
  28. Lock - Spinlock used to implement atomicity.
  29. Return Value:
  30. An ennumerated type:
  31. ResultNegative if Addend is < 0 after increment.
  32. ResultZero if Addend is = 0 after increment.
  33. ResultPositive if Addend is > 0 after increment.
  34. --*/
  35. {
  36. LONG OldValue;
  37. OldValue = (LONG)ExInterlockedAddUlong((PULONG)Addend, 1, Lock);
  38. if (OldValue < -1)
  39. return ResultNegative;
  40. if (OldValue == -1)
  41. return ResultZero;
  42. if (OldValue > -1)
  43. return ResultPositive;
  44. }
  45. INTERLOCKED_RESULT
  46. ExInterlockedDecrementLong (
  47. IN PLONG Addend,
  48. IN PKSPIN_LOCK Lock
  49. )
  50. /*++
  51. Routine Description:
  52. This function atomically decrements Addend, returning an ennumerated
  53. type which indicates what interesting transitions in the value of
  54. Addend occurred due the operation.
  55. Arguments:
  56. Addend - Pointer to variable to decrement.
  57. Lock - Spinlock used to implement atomicity.
  58. Return Value:
  59. An ennumerated type:
  60. ResultNegative if Addend is < 0 after decrement.
  61. ResultZero if Addend is = 0 after decrement.
  62. ResultPositive if Addend is > 0 after decrement.
  63. --*/
  64. {
  65. LONG OldValue;
  66. OldValue = (LONG)ExInterlockedAddUlong((PULONG)Addend, -1, Lock);
  67. if (OldValue > 1)
  68. return ResultPositive;
  69. if (OldValue == 1)
  70. return ResultZero;
  71. if (OldValue < 1)
  72. return ResultNegative;
  73. }