The Labs \ Source Viewer \ SSCLI \ System.Threading \ LockCookie

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** Class:    LockCookie
  18. **
  19. **
  20. ** Purpose: Defines the lock that implements
  21. **          single-writer/multiple-reader semantics
  22. **
  23. **
  24. ===========================================================*/
  25. namespace System.Threading
  26. {
  27.    
  28.     using System;
  29.     [System.Runtime.InteropServices.ComVisible(true)]
  30.     public struct LockCookie
  31.     {
  32.         private int _dwFlags;
  33.         private int _dwWriterSeqNum;
  34.         private int _wReaderAndWriterLevel;
  35.         private int _dwThreadID;
  36.        
  37.         public override int GetHashCode()
  38.         {
  39.             return _dwFlags + _dwWriterSeqNum + _wReaderAndWriterLevel + _dwThreadID;
  40.         }
  41.        
  42.         public override bool Equals(object obj)
  43.         {
  44.             if (obj is LockCookie)
  45.                 return Equals((LockCookie)obj);
  46.             else
  47.                 return false;
  48.         }
  49.        
  50.         public bool Equals(LockCookie obj)
  51.         {
  52.             return obj._dwFlags == _dwFlags && obj._dwWriterSeqNum == _dwWriterSeqNum && obj._wReaderAndWriterLevel == _wReaderAndWriterLevel && obj._dwThreadID == _dwThreadID;
  53.         }
  54.        
  55.         public static bool operator ==(LockCookie a, LockCookie b)
  56.         {
  57.             return a.Equals(b);
  58.         }
  59.        
  60.         public static bool operator !=(LockCookie a, LockCookie b)
  61.         {
  62.             return !(a == b);
  63.         }
  64.     }
  65. }

Developer Fusion