Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Collections;
- using System.Collections.Generic;
- namespace Uber.Collections
- {
- /// <summary>
- /// Implements thread-safe access for Enumerating through a collection of items
- /// </summary>
- /// <typeparam name="T">Items</typeparam>
- ///
- public class SafeEnumerator<T> : IEnumerator<T>
- {
- private readonly IEnumerator<T> m_Inner;
- private readonly ReaderWriterLockSlim m_Lock;
- public SafeEnumerator(IEnumerator<T> inner, ReaderWriterLockSlim @lock)
- {
- m_Inner = inner;
- m_Lock = @lock;
- m_Lock.EnterReadLock();
- }
- /// <summary>
- /// Implementation of IDisposable
- /// </summary>
- public void Dispose()
- {
- m_Lock.ExitReadLock();
- }
- /// <summary>
- /// Implementation of the Enumeration
- /// </summary>
- /// <returns></returns>
- public bool MoveNext()
- {
- return m_Inner.MoveNext();
- }
- public void Reset()
- {
- m_Inner.Reset();
- }
- public T Current
- {
- get { return m_Inner.Current; }
- }
- object IEnumerator.Current
- {
- get { return Current; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement