| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
- {
- internal class AppletFifo<T> : IAppletFifo<T>
- {
- private ConcurrentQueue<T> _dataQueue;
- public event EventHandler DataAvailable;
- public bool IsSynchronized
- {
- get { return ((ICollection)_dataQueue).IsSynchronized; }
- }
- public object SyncRoot
- {
- get { return ((ICollection)_dataQueue).SyncRoot; }
- }
- public int Count
- {
- get { return _dataQueue.Count; }
- }
- public AppletFifo()
- {
- _dataQueue = new ConcurrentQueue<T>();
- }
- public void Push(T item)
- {
- _dataQueue.Enqueue(item);
- DataAvailable?.Invoke(this, null);
- }
- public bool TryAdd(T item)
- {
- try
- {
- this.Push(item);
- return true;
- }
- catch
- {
- return false;
- }
- }
- public T Pop()
- {
- if (_dataQueue.TryDequeue(out T result))
- {
- return result;
- }
- throw new InvalidOperationException("FIFO empty.");
- }
- public bool TryPop(out T result)
- {
- return _dataQueue.TryDequeue(out result);
- }
- public bool TryTake(out T item)
- {
- return this.TryPop(out item);
- }
- public T Peek()
- {
- if (_dataQueue.TryPeek(out T result))
- {
- return result;
- }
- throw new InvalidOperationException("FIFO empty.");
- }
- public bool TryPeek(out T result)
- {
- return _dataQueue.TryPeek(out result);
- }
- public void Clear()
- {
- _dataQueue.Clear();
- }
- public T[] ToArray()
- {
- return _dataQueue.ToArray();
- }
- public void CopyTo(T[] array, int arrayIndex)
- {
- _dataQueue.CopyTo(array, arrayIndex);
- }
- public void CopyTo(Array array, int index)
- {
- this.CopyTo((T[])array, index);
- }
- public IEnumerator<T> GetEnumerator()
- {
- return _dataQueue.GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return _dataQueue.GetEnumerator();
- }
- }
- }
|