Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lockcookie.cs « threading « system « mscorlib « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32c9760976fe981193658c3c75ff59402cef2bfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
//
// <OWNER>Microsoft</OWNER>
/*============================================================
**
** Class:    LockCookie
**
**
** Purpose: Defines the lock that implements 
**          single-writer/multiple-reader semantics
**
**
===========================================================*/

namespace System.Threading {

    using System;
    [System.Runtime.InteropServices.ComVisible(true)]
    public struct LockCookie
    {
        private int _dwFlags;
        private int _dwWriterSeqNum;
        private int _wReaderAndWriterLevel;
        private int _dwThreadID;

        public override int GetHashCode()
        {
            // review - Microsoft!
            return _dwFlags + _dwWriterSeqNum + _wReaderAndWriterLevel + _dwThreadID;
        }
        
        public override bool Equals(Object obj)
        {
            if (obj is LockCookie)
                return Equals((LockCookie)obj);
            else
                return false;
        }
        
        public bool Equals(LockCookie obj)
        {
            return obj._dwFlags == _dwFlags && obj._dwWriterSeqNum == _dwWriterSeqNum &&
                obj._wReaderAndWriterLevel == _wReaderAndWriterLevel && obj._dwThreadID == _dwThreadID;
        }
        
        public static bool operator ==(LockCookie a, LockCookie b)
        {
            return a.Equals(b);
        }
        
        public static bool operator !=(LockCookie a, LockCookie b)
        {
            return !(a == b);
        }
    }
}