mscorlib(4.0.0.0) API with additions
ReaderWriterLock.cs
4 using System.Security;
6 
7 namespace System.Threading
8 {
10  [ComVisible(true)]
11  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
13  {
14  private IntPtr _hWriterEvent;
15 
16  private IntPtr _hReaderEvent;
17 
18  private IntPtr _hObjectHandle;
19 
20  private int _dwState;
21 
22  private int _dwULockID;
23 
24  private int _dwLLockID;
25 
26  private int _dwWriterID;
27 
28  private int _dwWriterSeqNum;
29 
30  private short _wWriterLevel;
31 
35  public bool IsReaderLockHeld
36  {
37  [SecuritySafeCritical]
38  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
39  get
40  {
41  return PrivateGetIsReaderLockHeld();
42  }
43  }
44 
48  public bool IsWriterLockHeld
49  {
50  [SecuritySafeCritical]
51  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
52  get
53  {
54  return PrivateGetIsWriterLockHeld();
55  }
56  }
57 
60  public int WriterSeqNum
61  {
62  [SecuritySafeCritical]
63  get
64  {
65  return PrivateGetWriterSeqNum();
66  }
67  }
68 
70  [SecuritySafeCritical]
72  {
73  PrivateInitialize();
74  }
75 
77  [SecuritySafeCritical]
79  {
80  PrivateDestruct();
81  }
82 
83  [MethodImpl(MethodImplOptions.InternalCall)]
84  [SecurityCritical]
85  private extern void AcquireReaderLockInternal(int millisecondsTimeout);
86 
92  [SecuritySafeCritical]
93  public void AcquireReaderLock(int millisecondsTimeout)
94  {
95  AcquireReaderLockInternal(millisecondsTimeout);
96  }
97 
104  [SecuritySafeCritical]
105  public void AcquireReaderLock(TimeSpan timeout)
106  {
107  long num = (long)timeout.TotalMilliseconds;
108  if (num < -1 || num > int.MaxValue)
109  {
110  throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
111  }
112  AcquireReaderLockInternal((int)num);
113  }
114 
115  [MethodImpl(MethodImplOptions.InternalCall)]
116  [SecurityCritical]
117  private extern void AcquireWriterLockInternal(int millisecondsTimeout);
118 
124  [SecuritySafeCritical]
125  public void AcquireWriterLock(int millisecondsTimeout)
126  {
127  AcquireWriterLockInternal(millisecondsTimeout);
128  }
129 
136  [SecuritySafeCritical]
137  public void AcquireWriterLock(TimeSpan timeout)
138  {
139  long num = (long)timeout.TotalMilliseconds;
140  if (num < -1 || num > int.MaxValue)
141  {
142  throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
143  }
144  AcquireWriterLockInternal((int)num);
145  }
146 
147  [MethodImpl(MethodImplOptions.InternalCall)]
148  [SecurityCritical]
149  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
150  private extern void ReleaseReaderLockInternal();
151 
154  [SecuritySafeCritical]
155  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
156  public void ReleaseReaderLock()
157  {
158  ReleaseReaderLockInternal();
159  }
160 
161  [MethodImpl(MethodImplOptions.InternalCall)]
162  [SecurityCritical]
163  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
164  private extern void ReleaseWriterLockInternal();
165 
168  [SecuritySafeCritical]
169  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
170  public void ReleaseWriterLock()
171  {
172  ReleaseWriterLockInternal();
173  }
174 
181  [SecuritySafeCritical]
182  public LockCookie UpgradeToWriterLock(int millisecondsTimeout)
183  {
184  LockCookie result = default(LockCookie);
185  FCallUpgradeToWriterLock(ref result, millisecondsTimeout);
186  return result;
187  }
188 
189  [MethodImpl(MethodImplOptions.InternalCall)]
190  [SecurityCritical]
191  private extern void FCallUpgradeToWriterLock(ref LockCookie result, int millisecondsTimeout);
192 
201  {
202  long num = (long)timeout.TotalMilliseconds;
203  if (num < -1 || num > int.MaxValue)
204  {
205  throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
206  }
207  return UpgradeToWriterLock((int)num);
208  }
209 
210  [MethodImpl(MethodImplOptions.InternalCall)]
211  [SecurityCritical]
212  private extern void DowngradeFromWriterLockInternal(ref LockCookie lockCookie);
213 
218  [SecuritySafeCritical]
219  public void DowngradeFromWriterLock(ref LockCookie lockCookie)
220  {
221  DowngradeFromWriterLockInternal(ref lockCookie);
222  }
223 
226  [SecuritySafeCritical]
228  {
229  LockCookie result = default(LockCookie);
230  FCallReleaseLock(ref result);
231  return result;
232  }
233 
234  [MethodImpl(MethodImplOptions.InternalCall)]
235  [SecurityCritical]
236  private extern void FCallReleaseLock(ref LockCookie result);
237 
238  [MethodImpl(MethodImplOptions.InternalCall)]
239  [SecurityCritical]
240  private extern void RestoreLockInternal(ref LockCookie lockCookie);
241 
245  [SecuritySafeCritical]
246  public void RestoreLock(ref LockCookie lockCookie)
247  {
248  RestoreLockInternal(ref lockCookie);
249  }
250 
251  [MethodImpl(MethodImplOptions.InternalCall)]
252  [SecurityCritical]
253  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
254  private extern bool PrivateGetIsReaderLockHeld();
255 
256  [MethodImpl(MethodImplOptions.InternalCall)]
257  [SecurityCritical]
258  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
259  private extern bool PrivateGetIsWriterLockHeld();
260 
261  [MethodImpl(MethodImplOptions.InternalCall)]
262  [SecurityCritical]
263  private extern int PrivateGetWriterSeqNum();
264 
269  [MethodImpl(MethodImplOptions.InternalCall)]
270  [SecuritySafeCritical]
271  public extern bool AnyWritersSince(int seqNum);
272 
273  [MethodImpl(MethodImplOptions.InternalCall)]
274  [SecurityCritical]
275  private extern void PrivateInitialize();
276 
277  [MethodImpl(MethodImplOptions.InternalCall)]
278  [SecurityCritical]
279  private extern void PrivateDestruct();
280  }
281 }
ReaderWriterLock()
Initializes a new instance of the T:System.Threading.ReaderWriterLock class.
bool AnyWritersSince(int seqNum)
Indicates whether the writer lock has been granted to any thread since the sequence number was obtain...
void ReleaseWriterLock()
Decrements the lock count on the writer lock.
void ReleaseReaderLock()
Decrements the lock count.
void AcquireReaderLock(int millisecondsTimeout)
Acquires a reader lock, using an T:System.Int32 value for the time-out.
Ensures that all finalization code in derived classes is marked as critical.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
double TotalMilliseconds
Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional milliseco...
Definition: TimeSpan.cs:180
Defines a lock that supports single writers and multiple readers.
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
void RestoreLock(ref LockCookie lockCookie)
Restores the lock status of the thread to what it was before calling M:System.Threading....
LockCookie UpgradeToWriterLock(int millisecondsTimeout)
Upgrades a reader lock to the writer lock, using an Int32 value for the time-out.
void AcquireWriterLock(TimeSpan timeout)
Acquires the writer lock, using a T:System.TimeSpan value for the time-out.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
void AcquireWriterLock(int millisecondsTimeout)
Acquires the writer lock, using an T:System.Int32 value for the time-out.
MethodImplOptions
Defines the details of how a method is implemented.
void AcquireReaderLock(TimeSpan timeout)
Acquires a reader lock, using a T:System.TimeSpan value for the time-out.
bool IsWriterLockHeld
Gets a value indicating whether the current thread holds the writer lock.
LockCookie UpgradeToWriterLock(TimeSpan timeout)
Upgrades a reader lock to the writer lock, using a TimeSpan value for the time-out.
bool IsReaderLockHeld
Gets a value indicating whether the current thread holds a reader lock.
void DowngradeFromWriterLock(ref LockCookie lockCookie)
Restores the lock status of the thread to what it was before M:System.Threading.ReaderWriterLock....
int WriterSeqNum
Gets the current sequence number.
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
LockCookie ReleaseLock()
Releases the lock, regardless of the number of times the thread acquired the lock.