History

Updated InterprocessCache to properly report excessive timeout/lock exceptions.

ritchiecarroll committed 12 years ago

Commit 26c40741 parent df2dfa22 files · +47 −16Browse files

Showing the changes to Source/Libraries/GSF.Core/Threading/InterprocessReaderWriterLock.cs (1 of 2 files). Show all

Unified · Split

Source/Libraries/GSF.Core/Threading/InterprocessReaderWriterLock.cs+21−7
@@ -16,7 +16,7 @@ · 15 unmodified lines
1616 //
1717 // Code Modification History:
1818 // ----------------------------------------------------------------------------------------------------
19−// 03/21/2011 - Ritchie
19+// 03/21/2011 - J. Ritchie Carroll
2020 // Generated original version of source code.
2121 // 12/14/2012 - Starlynn Danyelle Gilliam
2222 // Modified Header.
@@ -203,8 +203,14 @@ namespace GSF.Threading · 180 unmodified lines
203203 /// <param name="millisecondsTimeout">The number of milliseconds to wait, or -1 (<see cref="Timeout.Infinite"/>) to wait indefinitely.</param>
204204 /// <returns><c>true</c> if the calling thread entered read mode, otherwise, <c>false</c>.</returns>
205205 /// <remarks>
206+ /// <para>
206207 /// Upon successful acquisition of a read lock, use the <c>finally</c> block of a <c>try/finally</c> statement to call <see cref="ExitReadLock"/>.
207208 /// One <see cref="ExitReadLock"/> should be called for each <see cref="EnterReadLock"/> or <see cref="TryEnterReadLock"/>.
209+ /// </para>
210+ /// <para>
211+ /// Note that this function may wait as long as 2 * <paramref name="millisecondsTimeout"/> since the function first waits for synchronous access
212+ /// to the semaphore, then waits again on an available semaphore slot.
213+ /// </para>
208214 /// </remarks>
209215 public bool TryEnterReadLock(int millisecondsTimeout)
210216 {
@@ -213,7 +219,8 @@ namespace GSF.Threading · 2 unmodified lines
213219 try
214220 {
215221 // Wait for system level mutex lock to synchronize access to semaphore
216− m_semaphoreLock.WaitOne();
222+ if (!m_semaphoreLock.WaitOne(millisecondsTimeout))
223+ return false;
217224 }
218225 catch (AbandonedMutexException)
219226 {
@@ -241,8 +248,14 @@ namespace GSF.Threading · 21 unmodified lines
241248 /// <param name="millisecondsTimeout">The number of milliseconds to wait, or -1 (<see cref="Timeout.Infinite"/>) to wait indefinitely.</param>
242249 /// <returns><c>true</c> if the calling thread entered write mode, otherwise, <c>false</c>.</returns>
243250 /// <remarks>
244− /// Upon successful aquistion of a write lock, use the <c>finally</c> block of a <c>try/finally</c> statement to call <see cref="ExitWriteLock"/>.
251+ /// <para>
252+ /// Upon successful acquisition of a write lock, use the <c>finally</c> block of a <c>try/finally</c> statement to call <see cref="ExitWriteLock"/>.
245253 /// One <see cref="ExitWriteLock"/> should be called for each <see cref="EnterWriteLock"/> or <see cref="TryEnterWriteLock"/>.
254+ /// </para>
255+ /// <para>
256+ /// Note that this function may wait as long as 2 * <paramref name="millisecondsTimeout"/> since the function first waits for synchronous access
257+ /// to the semaphore, then waits again on an available semaphore slot.
258+ /// </para>
246259 /// </remarks>
247260 public bool TryEnterWriteLock(int millisecondsTimeout)
248261 {
@@ -252,7 +265,8 @@ namespace GSF.Threading · 3 unmodified lines
252265 try
253266 {
254267 // Wait for system level mutex lock to synchronize access to semaphore
255− m_semaphoreLock.WaitOne();
268+ if (!m_semaphoreLock.WaitOne(millisecondsTimeout))
269+ return false;
256270 }
257271 catch (AbandonedMutexException)
258272 {
@@ -262,7 +276,7 @@ namespace GSF.Threading · 3 unmodified lines
262276
263277 try
264278 {
265− // At this point no other threads can aquire read or write access since we own the mutex.
279+ // At this point no other threads can acquire read or write access since we own the mutex.
266280 // Other threads may be busy reading, so we wait until all semaphore slots become available.
267281 // The only way to get a semaphore slot count is to execute a successful wait and release.
268282 startTime = DateTime.UtcNow.Ticks;
@@ -281,7 +295,7 @@ namespace GSF.Threading · 12 unmodified lines
281295 // Sleep to allow any remaining reads to complete
282296 Thread.Sleep(1);
283297
284− // Continue to adjust remaining time to accomodate user specified millisecond timeout
298+ // Continue to adjust remaining time to accommodate user specified millisecond timeout
285299 if (millisecondsTimeout > 0)
286300 adjustedTimeout = millisecondsTimeout - (int)Ticks.ToMilliseconds(DateTime.UtcNow.Ticks - startTime);
287301
@@ -302,7 +316,7 @@ namespace GSF.Threading · 14 unmodified lines
302316 m_semaphoreLock.ReleaseMutex();
303317 }
304318
305− // Successfully entering write lock leaves state of semphore locking mutex "owned", it is critical that
319+ // Successfully entering write lock leaves state of semaphore locking mutex "owned", it is critical that
306320 // consumer call ExitWriteLock upon completion of write action to release mutex regardless of whether
307321 // their code succeeds or fails, that is, consumer should use the finally clause of a "try/finally"
308322 // expression to ExitWriteLock.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t