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.

96 lines
2.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1990 - 2000
  6. //
  7. // File: CompFlag.hxx
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. File : CompFlag.hxx
  12. Title : Implementation of a flag set.
  13. History :
  14. KamenM - 01/04/2000 - Created.
  15. -------------------------------------------------------------------- */
  16. #ifndef __COMPFLAG_HXX__
  17. #define __COMPFLAG_HXX__
  18. class CompositeFlags
  19. {
  20. public:
  21. inline CompositeFlags(void)
  22. {
  23. Flags = 0;
  24. }
  25. inline void SetFlagUnsafe(unsigned int FlagConstant)
  26. {
  27. Flags |= FlagConstant;
  28. }
  29. inline void SetFlagWithMutex(unsigned int FlagConstant, MUTEX *Mutex)
  30. {
  31. Mutex->Request();
  32. SetFlagUnsafe(FlagConstant);
  33. Mutex->Clear();
  34. }
  35. inline void SetFlagInterlocked(unsigned int FlagConstant)
  36. {
  37. unsigned int NewFlags, OldFlags;
  38. do
  39. {
  40. OldFlags = Flags;
  41. NewFlags = Flags | FlagConstant;
  42. }
  43. while (InterlockedCompareExchange((long *)&Flags, NewFlags, OldFlags) != (long)OldFlags);
  44. }
  45. inline void ClearFlagUnsafe(unsigned int FlagConstant)
  46. {
  47. Flags &= ~FlagConstant;
  48. }
  49. inline void ClearFlagWithMutex(unsigned int FlagConstant, MUTEX *Mutex)
  50. {
  51. Mutex->Request();
  52. ClearFlagUnsafe(FlagConstant);
  53. Mutex->Clear();
  54. }
  55. inline void ClearFlagInterlocked(unsigned int FlagConstant)
  56. {
  57. unsigned int NewFlags, OldFlags;
  58. do
  59. {
  60. OldFlags = Flags;
  61. NewFlags = Flags & (~FlagConstant);
  62. }
  63. while (InterlockedCompareExchange((long *)&Flags, NewFlags, OldFlags) != (long)OldFlags);
  64. }
  65. inline BOOL GetFlag(unsigned int FlagConstant)
  66. {
  67. return (Flags & FlagConstant);
  68. }
  69. // used for reinitialization of cached objects
  70. inline void ClearAll (void)
  71. {
  72. Flags = 0;
  73. }
  74. private:
  75. unsigned int Flags;
  76. };
  77. #endif // __COMPFLAG_HXX__