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.

76 lines
1.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. intbits.c
  5. Abstract:
  6. This module contains routines to do interlocked bit manipulation
  7. Author:
  8. Neill Clift (NeillC) 12-May-2000
  9. Environment:
  10. User and kernel mode.
  11. Revision History:
  12. Rob Earhart (earhart) October 13, 2000
  13. Moved from Ex to Rtl
  14. --*/
  15. #include "ntrtlp.h"
  16. #pragma hdrstop
  17. ULONG
  18. FASTCALL
  19. RtlInterlockedSetClearBits (
  20. IN OUT PULONG Flags,
  21. IN ULONG sFlag,
  22. IN ULONG cFlag
  23. )
  24. /*++
  25. Routine Description:
  26. This function atomically sets and clears the specified flags in the target
  27. Arguments:
  28. Flags - Pointer to variable containing current mask.
  29. sFlag - Flags to set in target
  30. CFlag - Flags to clear in target
  31. Return Value:
  32. ULONG - Old value of mask before modification
  33. --*/
  34. {
  35. ULONG NewFlags, OldFlags;
  36. OldFlags = *Flags;
  37. NewFlags = (OldFlags | sFlag) & ~cFlag;
  38. while (NewFlags != OldFlags) {
  39. NewFlags = InterlockedCompareExchange ((PLONG) Flags, (LONG) NewFlags, (LONG) OldFlags);
  40. if (NewFlags == OldFlags) {
  41. break;
  42. }
  43. OldFlags = NewFlags;
  44. NewFlags = (NewFlags | sFlag) & ~cFlag;
  45. }
  46. return OldFlags;
  47. }