2019-11-14 00:18:44 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
|
|
|
|
|
{
|
2019-11-18 06:16:26 -05:00
|
|
|
|
internal class AppletFifo<T> : IAppletFifo<T>
|
2019-11-14 00:18:44 -05:00
|
|
|
|
{
|
|
|
|
|
private ConcurrentQueue<T> _dataQueue;
|
|
|
|
|
|
2019-11-18 06:16:26 -05:00
|
|
|
|
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; }
|
|
|
|
|
}
|
2019-11-14 00:18:44 -05:00
|
|
|
|
|
|
|
|
|
public AppletFifo()
|
|
|
|
|
{
|
|
|
|
|
_dataQueue = new ConcurrentQueue<T>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Push(T item)
|
|
|
|
|
{
|
|
|
|
|
_dataQueue.Enqueue(item);
|
2019-11-18 06:16:26 -05:00
|
|
|
|
|
|
|
|
|
DataAvailable?.Invoke(this, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryAdd(T item)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this.Push(item);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-11-14 00:18:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-18 06:16:26 -05:00
|
|
|
|
public bool TryTake(out T item)
|
|
|
|
|
{
|
|
|
|
|
return this.TryPop(out item);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-14 00:18:44 -05:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-18 06:16:26 -05:00
|
|
|
|
public void CopyTo(Array array, int index)
|
|
|
|
|
{
|
|
|
|
|
this.CopyTo((T[])array, index);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-14 00:18:44 -05:00
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return _dataQueue.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return _dataQueue.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|