17 using System.Collections;
18 using System.Collections.Generic;
19 using System.Threading;
32 private readonly List<T> _list;
34 private readonly ReaderWriterLockSlim _listLock =
new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
36 private T _mostRecentlyRemoved;
54 _list =
new List<T>(size);
67 _listLock.EnterReadLock();
72 _listLock.ExitReadLock();
90 _listLock.EnterReadLock();
95 _listLock.ExitReadLock();
109 _listLock.EnterReadLock();
114 _listLock.ExitReadLock();
130 _listLock.EnterReadLock();
132 if (_samples <= _size)
136 return _mostRecentlyRemoved;
140 _listLock.ExitReadLock();
152 public T
this [
int i]
158 _listLock.EnterReadLock();
165 if (i > _list.Count - 1)
169 _listLock.ExitReadLock();
171 _listLock.EnterReadLock();
177 return _list[(_list.Count + _tail - i - 1) % _list.Count];
181 _listLock.ExitReadLock();
188 _listLock.EnterWriteLock();
195 if (i > _list.Count - 1)
202 var count = _list.Count;
203 for (var j = 0; j < i - count + 1; j++)
209 _list[(_list.Count + _tail - i - 1) % _list.Count] = value;
213 _listLock.ExitWriteLock();
228 _listLock.EnterReadLock();
229 return _samples >= _size;
233 _listLock.ExitReadLock();
249 var temp =
new List<T>(_list.Count);
252 _listLock.EnterReadLock();
254 for (
int i = 0; i < _list.Count; i++)
258 return temp.GetEnumerator();
262 _listLock.ExitReadLock();
274 IEnumerator IEnumerable.GetEnumerator()
287 _listLock.EnterWriteLock();
290 if (_size == _list.Count)
294 _mostRecentlyRemoved = _list[_tail];
296 _tail = (_tail + 1) % _size;
305 _listLock.ExitWriteLock();
316 _listLock.EnterWriteLock();
324 _listLock.ExitWriteLock();
328 private void Resize(
int size)
332 _listLock.EnterWriteLock();
334 _list.EnsureCapacity(size);
335 if (size < _list.Count)
337 _list.RemoveRange(0, _list.Count - size);
343 _listLock.ExitWriteLock();