mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Add project files.
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.Dispatcher
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal abstract class Dispatcher
|
||||
{
|
||||
private static Interconnect s_interconnect = new Interconnect();
|
||||
[ThreadStatic]
|
||||
private static Dispatcher s_threadDispatcher;
|
||||
private static NamedPipeClientStream _debugPipe;
|
||||
private static BinaryWriter _debugPipeWriter;
|
||||
private static BinaryReader _debugPipeReader;
|
||||
private Thread _owningThread;
|
||||
private uint _enterCount;
|
||||
private Feeder _feeder;
|
||||
private int _feederReadStamp;
|
||||
private int _feederWriteStamp;
|
||||
|
||||
public Dispatcher()
|
||||
{
|
||||
_owningThread = Thread.CurrentThread;
|
||||
_feeder = EnterDispatch();
|
||||
}
|
||||
|
||||
public void FinalStopDispatch()
|
||||
{
|
||||
LeaveDispatch();
|
||||
_feeder = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_enterCount != 1U)
|
||||
return;
|
||||
LeaveDispatch();
|
||||
}
|
||||
|
||||
public static Dispatcher CurrentDispatcher => s_threadDispatcher;
|
||||
|
||||
public static void PostItem_AnyThread(Thread thread, QueueItem item, int priority)
|
||||
{
|
||||
if (thread == null || thread == Thread.CurrentThread)
|
||||
{
|
||||
Dispatcher currentDispatcher = CurrentDispatcher;
|
||||
if (currentDispatcher != null)
|
||||
{
|
||||
currentDispatcher.PostItem_SameThread(item, priority);
|
||||
return;
|
||||
}
|
||||
}
|
||||
s_interconnect.PostItem(thread, item, priority);
|
||||
}
|
||||
|
||||
public Thread DispatchThread => _owningThread;
|
||||
|
||||
public void MainLoop(Queue queue)
|
||||
{
|
||||
EnterDispatch();
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
QueueItem nextItem = queue.GetNextItem();
|
||||
if (nextItem != null)
|
||||
{
|
||||
SendDebugMessage(nextItem.ToDebugPacketString());
|
||||
nextItem.Dispatch();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
LeaveDispatch();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void PostItem_SameThread(QueueItem item, int priority);
|
||||
|
||||
protected abstract void PostItems_SameThread(QueueItem.FIFO items, int priority);
|
||||
|
||||
protected abstract void WakeDispatchThread();
|
||||
|
||||
private Feeder EnterDispatch()
|
||||
{
|
||||
bool isRoot = _enterCount == 0U;
|
||||
++_enterCount;
|
||||
if (isRoot)
|
||||
s_threadDispatcher = this;
|
||||
return s_interconnect.EnterDispatch(this, isRoot);
|
||||
}
|
||||
|
||||
private void LeaveDispatch()
|
||||
{
|
||||
--_enterCount;
|
||||
bool isRoot = _enterCount == 0U;
|
||||
if (isRoot)
|
||||
s_threadDispatcher = null;
|
||||
s_interconnect.LeaveDispatch(this, isRoot);
|
||||
}
|
||||
|
||||
public void NotifyFeederItems()
|
||||
{
|
||||
if (Thread.CurrentThread == _owningThread)
|
||||
return;
|
||||
Interlocked.Increment(ref _feederWriteStamp);
|
||||
WakeDispatchThread();
|
||||
}
|
||||
|
||||
internal bool DrainFeeder()
|
||||
{
|
||||
int feederWriteStamp = _feederWriteStamp;
|
||||
if (feederWriteStamp == _feederReadStamp)
|
||||
return false;
|
||||
bool flag = false;
|
||||
_feederReadStamp = feederWriteStamp;
|
||||
QueueItem.FIFO[] recycled = _feeder.HandoffFIFOs();
|
||||
if (recycled != null)
|
||||
{
|
||||
for (int priority = 0; priority < recycled.Length; ++priority)
|
||||
{
|
||||
QueueItem.FIFO items = recycled[priority];
|
||||
if (items != null)
|
||||
{
|
||||
PostItems_SameThread(items, priority);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
_feeder.RecycleFIFOs(recycled);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private static NamedPipeClientStream DebugPipe
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_debugPipe == null && Application.IsDebug)
|
||||
{
|
||||
_debugPipe = new NamedPipeClientStream(System.Reflection.Assembly.GetExecutingAssembly().FullName);
|
||||
_debugPipe.Connect();
|
||||
}
|
||||
return _debugPipe;
|
||||
}
|
||||
}
|
||||
|
||||
private static BinaryWriter DebugPipeWriter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_debugPipe != null && _debugPipeWriter == null)
|
||||
_debugPipeWriter = new BinaryWriter(DebugPipe);
|
||||
return _debugPipeWriter;
|
||||
}
|
||||
}
|
||||
|
||||
private static BinaryReader DebugPipeReader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_debugPipe != null && _debugPipeReader == null)
|
||||
_debugPipeReader = new BinaryReader(DebugPipe);
|
||||
return _debugPipeReader;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message via <see cref="debugPipe"/>
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void SendDebugMessage(string message)
|
||||
{
|
||||
if (Application.IsDebug && DebugPipe.IsConnected && DebugPipe.CanWrite)
|
||||
{
|
||||
DebugPipe.WriteByte(0x01);
|
||||
byte[] buffer = System.Text.Encoding.Unicode.GetBytes(message);
|
||||
DebugPipe.Write(BitConverter.GetBytes(buffer.Length), 0, sizeof(int));
|
||||
DebugPipe.Write(buffer, 0, buffer.Length);
|
||||
DebugPipe.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.Feeder
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal class Feeder
|
||||
{
|
||||
private Dispatcher _dispatcher;
|
||||
private bool _hasItems;
|
||||
private QueueItem.FIFO[] _fifos;
|
||||
|
||||
public bool HasItems => _hasItems;
|
||||
|
||||
public void EnterDispatch(Dispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
if (!_hasItems)
|
||||
return;
|
||||
_dispatcher.NotifyFeederItems();
|
||||
}
|
||||
|
||||
public void LeaveDispatch(Dispatcher dispatcher) => _dispatcher = null;
|
||||
|
||||
public void PostItem(QueueItem item, int priority)
|
||||
{
|
||||
bool flag = false;
|
||||
lock (this)
|
||||
{
|
||||
if (_fifos == null)
|
||||
_fifos = new QueueItem.FIFO[32];
|
||||
(_fifos[priority] ?? (_fifos[priority] = new QueueItem.FIFO())).Append(item);
|
||||
if (!_hasItems)
|
||||
{
|
||||
_hasItems = true;
|
||||
if (_dispatcher != null)
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
return;
|
||||
_dispatcher.NotifyFeederItems();
|
||||
}
|
||||
|
||||
public QueueItem.FIFO[] HandoffFIFOs()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
QueueItem.FIFO[] fifos = _fifos;
|
||||
_fifos = null;
|
||||
_hasItems = false;
|
||||
return fifos;
|
||||
}
|
||||
}
|
||||
|
||||
public void RecycleFIFOs(QueueItem.FIFO[] recycled)
|
||||
{
|
||||
if (_fifos != null)
|
||||
return;
|
||||
lock (this)
|
||||
{
|
||||
if (_fifos != null)
|
||||
return;
|
||||
_fifos = recycled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.Interconnect
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal class Interconnect
|
||||
{
|
||||
private Map<Thread, Feeder> _feeders;
|
||||
|
||||
public Interconnect() => _feeders = new Map<Thread, Feeder>();
|
||||
|
||||
private Feeder GetFeeder(Thread thread, bool lazyCreate)
|
||||
{
|
||||
if (thread == null)
|
||||
thread = Thread.CurrentThread;
|
||||
lock (this)
|
||||
{
|
||||
Feeder feeder;
|
||||
if (!_feeders.TryGetValue(thread, out feeder) && lazyCreate)
|
||||
_feeders[thread] = feeder = new Feeder();
|
||||
return feeder;
|
||||
}
|
||||
}
|
||||
|
||||
public Feeder EnterDispatch(Dispatcher dispatcher, bool isRoot)
|
||||
{
|
||||
Feeder feeder = GetFeeder(Thread.CurrentThread, isRoot);
|
||||
if (isRoot)
|
||||
feeder.EnterDispatch(dispatcher);
|
||||
return feeder;
|
||||
}
|
||||
|
||||
public void LeaveDispatch(Dispatcher dispatcher, bool isRoot)
|
||||
{
|
||||
Thread currentThread = Thread.CurrentThread;
|
||||
Feeder feeder = GetFeeder(currentThread, false);
|
||||
if (!isRoot)
|
||||
return;
|
||||
feeder.LeaveDispatch(dispatcher);
|
||||
lock (this)
|
||||
_feeders.Remove(currentThread);
|
||||
if (!feeder.HasItems)
|
||||
return;
|
||||
dispatcher.DrainFeeder();
|
||||
}
|
||||
|
||||
public void PostItem(Thread thread, QueueItem item, int priority) => GetFeeder(thread, false)?.PostItem(item, priority);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.PriorityQueue
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal class PriorityQueue : Queue
|
||||
{
|
||||
public const int MAX_PRIORITIES = 32;
|
||||
private static readonly int[] s_lowestBitInNibble = new int[16]
|
||||
{
|
||||
4,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
0,
|
||||
1,
|
||||
0
|
||||
};
|
||||
private int _readyMask;
|
||||
private int _wakeMask;
|
||||
private int _hookMask;
|
||||
private int _lockMask;
|
||||
private int _allQueues;
|
||||
private Queue[] _queues;
|
||||
private PriorityQueue.HookProc _loopHook;
|
||||
private PriorityQueue.HookProc[] _drainHooks;
|
||||
|
||||
public PriorityQueue(uint count) : this(new Queue[count])
|
||||
{
|
||||
}
|
||||
|
||||
public PriorityQueue(Queue[] queues)
|
||||
{
|
||||
_allQueues = InitChildQueues(queues);
|
||||
_queues = queues;
|
||||
_drainHooks = new PriorityQueue.HookProc[queues.Length];
|
||||
_wakeMask = _allQueues;
|
||||
UpdateReadyMask();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
Queue[] queues = _queues;
|
||||
base.Dispose();
|
||||
if (queues == null)
|
||||
return;
|
||||
foreach (Queue queue in queues)
|
||||
queue?.Dispose();
|
||||
}
|
||||
|
||||
private int InitChildQueues(Queue[] queues)
|
||||
{
|
||||
int num = 0;
|
||||
for (int priority = 0; priority < queues.Length; ++priority)
|
||||
{
|
||||
Queue queue = queues[priority];
|
||||
if (queue == null)
|
||||
{
|
||||
queue = new SimpleQueue();
|
||||
queues[priority] = queue;
|
||||
}
|
||||
PriorityQueue.WakeProxy wakeProxy = new PriorityQueue.WakeProxy(this, priority, queue);
|
||||
num |= 1 << priority;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public Queue this[int priority] => _queues[priority];
|
||||
|
||||
public PriorityQueue.HookProc GetDrainHook(int priority) => _drainHooks[priority];
|
||||
|
||||
public void SetDrainHook(int priority, PriorityQueue.HookProc hook)
|
||||
{
|
||||
_drainHooks[priority] = hook;
|
||||
if (hook != null)
|
||||
_hookMask |= 1 << priority;
|
||||
else
|
||||
_hookMask &= ~(1 << priority);
|
||||
UpdateReadyMask();
|
||||
}
|
||||
|
||||
public PriorityQueue.HookProc LoopHook
|
||||
{
|
||||
get => _loopHook;
|
||||
set => _loopHook = value;
|
||||
}
|
||||
|
||||
public bool IsLocked(int priority) => (_lockMask & 1 << priority) != 0;
|
||||
|
||||
public void SetLock(int priority, bool value)
|
||||
{
|
||||
if (value)
|
||||
_lockMask |= 1 << priority;
|
||||
else
|
||||
_lockMask &= ~(1 << priority);
|
||||
UpdateReadyMask();
|
||||
}
|
||||
|
||||
public void LockAll(bool value)
|
||||
{
|
||||
if (value)
|
||||
_lockMask |= _allQueues;
|
||||
else
|
||||
_lockMask &= ~_allQueues;
|
||||
UpdateReadyMask();
|
||||
}
|
||||
|
||||
public Queue BuildSubsetQueue(int[] priorities, bool ignoreLocks)
|
||||
{
|
||||
int subsetMask = 0;
|
||||
for (int index = 0; index < priorities.Length; ++index)
|
||||
subsetMask |= 1 << priorities[index];
|
||||
return new PriorityQueue.SubsetQueue(this, subsetMask, ignoreLocks);
|
||||
}
|
||||
|
||||
public override QueueItem GetNextItem() => GetNextItemWorker(_allQueues, false);
|
||||
|
||||
private QueueItem GetNextItemWorker(int subsetMask, bool ignoreLocks)
|
||||
{
|
||||
int mask = BeginReadLoop(subsetMask, ignoreLocks);
|
||||
QueueItem queueItem = null;
|
||||
while (mask != 0)
|
||||
{
|
||||
int lowestBit = FindLowestBit(mask);
|
||||
queueItem = _queues[lowestBit].GetNextItem();
|
||||
if (queueItem == null)
|
||||
{
|
||||
SetWake(lowestBit, false);
|
||||
PriorityQueue.HookProc drainHook = _drainHooks[lowestBit];
|
||||
if (drainHook != null)
|
||||
{
|
||||
bool didWork;
|
||||
bool abort;
|
||||
drainHook(out didWork, out abort);
|
||||
if (!abort)
|
||||
{
|
||||
if (didWork)
|
||||
{
|
||||
mask = BeginReadLoop(subsetMask, ignoreLocks);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
mask &= ~(1 << lowestBit);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return queueItem;
|
||||
}
|
||||
|
||||
private int BeginReadLoop(int subsetMask, bool ignoreLocks)
|
||||
{
|
||||
if (!ignoreLocks)
|
||||
subsetMask &= ~_lockMask;
|
||||
subsetMask &= _wakeMask | _hookMask;
|
||||
if (subsetMask != 0 && _loopHook != null)
|
||||
{
|
||||
bool didWork;
|
||||
bool abort;
|
||||
_loopHook(out didWork, out abort);
|
||||
if (abort)
|
||||
subsetMask = 0;
|
||||
}
|
||||
return subsetMask;
|
||||
}
|
||||
|
||||
private void SetWake(int priority, bool value)
|
||||
{
|
||||
if (value)
|
||||
_wakeMask |= 1 << priority;
|
||||
else
|
||||
_wakeMask &= ~(1 << priority);
|
||||
UpdateReadyMask();
|
||||
}
|
||||
|
||||
private void UpdateReadyMask()
|
||||
{
|
||||
bool flag = _readyMask == 0;
|
||||
_readyMask = (_wakeMask | _hookMask) & ~_lockMask;
|
||||
if (!flag || _readyMask == 0)
|
||||
return;
|
||||
OnWake();
|
||||
}
|
||||
|
||||
private static int FindLowestBit(int mask)
|
||||
{
|
||||
int num = 0;
|
||||
if ((mask & ushort.MaxValue) == 0)
|
||||
{
|
||||
num += 16;
|
||||
mask >>= 16;
|
||||
}
|
||||
if ((mask & byte.MaxValue) == 0)
|
||||
{
|
||||
num += 8;
|
||||
mask >>= 8;
|
||||
}
|
||||
if ((mask & 15) == 0)
|
||||
{
|
||||
num += 4;
|
||||
mask >>= 4;
|
||||
}
|
||||
return num + s_lowestBitInNibble[mask & 15];
|
||||
}
|
||||
|
||||
public delegate void HookProc(out bool didWork, out bool abort);
|
||||
|
||||
private class SubsetQueue : Queue
|
||||
{
|
||||
private PriorityQueue _owner;
|
||||
private int _subsetMask;
|
||||
private bool _ignoreLocks;
|
||||
|
||||
public SubsetQueue(PriorityQueue owner, int subsetMask, bool ignoreLocks)
|
||||
{
|
||||
_owner = owner;
|
||||
_subsetMask = subsetMask;
|
||||
_ignoreLocks = ignoreLocks;
|
||||
}
|
||||
|
||||
public override QueueItem GetNextItem() => _owner.GetNextItemWorker(_subsetMask, _ignoreLocks);
|
||||
}
|
||||
|
||||
private class WakeProxy
|
||||
{
|
||||
private PriorityQueue _owner;
|
||||
private int _priority;
|
||||
|
||||
public WakeProxy(PriorityQueue owner, int priority, Queue queue)
|
||||
{
|
||||
_owner = owner;
|
||||
_priority = priority;
|
||||
queue.Wake += new EventHandler(OnChildWake);
|
||||
}
|
||||
|
||||
private void OnChildWake(object sender, EventArgs args) => _owner.SetWake(_priority, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.Queue
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal abstract class Queue
|
||||
{
|
||||
public abstract QueueItem GetNextItem();
|
||||
|
||||
public event EventHandler Wake;
|
||||
|
||||
protected virtual void OnWake()
|
||||
{
|
||||
if (Wake == null)
|
||||
return;
|
||||
Wake(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.QueueItem
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal abstract class QueueItem
|
||||
{
|
||||
protected QueueItem _prev;
|
||||
protected QueueItem _next;
|
||||
protected QueueItem.Chain _owner;
|
||||
|
||||
public bool IsPending => _owner != null;
|
||||
|
||||
public abstract void Dispatch();
|
||||
|
||||
public override string ToString() => GetType().Name;
|
||||
|
||||
public virtual string ToDebugPacketString() => ToString();
|
||||
|
||||
internal class Chain
|
||||
{
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
protected static void ValidateAdd(QueueItem item)
|
||||
{
|
||||
}
|
||||
|
||||
protected void ValidateRemove(QueueItem item)
|
||||
{
|
||||
}
|
||||
|
||||
protected void Link(QueueItem item, QueueItem anchor, bool before)
|
||||
{
|
||||
UpdateOwners(item, item, null, this);
|
||||
LinkItems(item, item, anchor, before);
|
||||
}
|
||||
|
||||
protected void Unlink(QueueItem item)
|
||||
{
|
||||
UnlinkItems(item, item);
|
||||
UpdateOwners(item, item, this, null);
|
||||
}
|
||||
|
||||
protected void TransferFromChain(
|
||||
QueueItem.Chain oldOwner,
|
||||
QueueItem first,
|
||||
QueueItem last,
|
||||
QueueItem anchor,
|
||||
bool before)
|
||||
{
|
||||
UnlinkItems(first, last);
|
||||
UpdateOwners(first, last, oldOwner, this);
|
||||
LinkItems(first, last, anchor, before);
|
||||
}
|
||||
|
||||
protected static bool IsOnlyChild(QueueItem item) => item._next == item;
|
||||
|
||||
protected static QueueItem NextItem(QueueItem item) => item._next;
|
||||
|
||||
protected static QueueItem PrevItem(QueueItem item) => item._prev;
|
||||
|
||||
private void LinkItems(QueueItem first, QueueItem last, QueueItem anchor, bool before)
|
||||
{
|
||||
QueueItem queueItem1 = last;
|
||||
QueueItem queueItem2 = first;
|
||||
if (anchor != null)
|
||||
{
|
||||
if (before)
|
||||
{
|
||||
queueItem1 = anchor._prev;
|
||||
queueItem2 = anchor;
|
||||
}
|
||||
else
|
||||
{
|
||||
queueItem1 = anchor;
|
||||
queueItem2 = anchor._next;
|
||||
}
|
||||
queueItem1._next = first;
|
||||
queueItem2._prev = last;
|
||||
}
|
||||
first._prev = queueItem1;
|
||||
last._next = queueItem2;
|
||||
}
|
||||
|
||||
private void UnlinkItems(QueueItem first, QueueItem last)
|
||||
{
|
||||
if (first._prev != last)
|
||||
{
|
||||
first._prev._next = last._next;
|
||||
last._next._prev = first._prev;
|
||||
}
|
||||
first._prev = null;
|
||||
last._next = null;
|
||||
}
|
||||
|
||||
private void UpdateOwners(
|
||||
QueueItem first,
|
||||
QueueItem last,
|
||||
QueueItem.Chain oldOwner,
|
||||
QueueItem.Chain newOwner)
|
||||
{
|
||||
QueueItem queueItem = first;
|
||||
while (true)
|
||||
{
|
||||
queueItem._owner = newOwner;
|
||||
if (queueItem != last)
|
||||
queueItem = queueItem._next;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
protected internal static void DEBUG_AssertLinked(QueueItem item)
|
||||
{
|
||||
}
|
||||
|
||||
public struct ChainEnumerator
|
||||
{
|
||||
private QueueItem _currentItem;
|
||||
private QueueItem _stopItem;
|
||||
|
||||
public ChainEnumerator(QueueItem tail)
|
||||
{
|
||||
_currentItem = null;
|
||||
_stopItem = tail;
|
||||
}
|
||||
|
||||
public QueueItem Current => _currentItem;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (_stopItem == null)
|
||||
{
|
||||
_currentItem = null;
|
||||
return false;
|
||||
}
|
||||
if (_currentItem != null)
|
||||
{
|
||||
if (_currentItem == _stopItem)
|
||||
{
|
||||
_currentItem = _stopItem = null;
|
||||
return false;
|
||||
}
|
||||
_currentItem = _currentItem._next;
|
||||
}
|
||||
else
|
||||
_currentItem = _stopItem._next;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class FIFO : QueueItem.Chain
|
||||
{
|
||||
private QueueItem _tail;
|
||||
|
||||
public QueueItem Head
|
||||
{
|
||||
get
|
||||
{
|
||||
QueueItem queueItem = null;
|
||||
if (_tail != null)
|
||||
queueItem = _tail._next;
|
||||
return queueItem;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
while (_tail != null)
|
||||
Remove(_tail);
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public bool Append(QueueItem item)
|
||||
{
|
||||
ValidateAdd(item);
|
||||
bool flag = _tail == null;
|
||||
Link(item, _tail, false);
|
||||
_tail = item;
|
||||
return flag;
|
||||
}
|
||||
|
||||
public bool Append(QueueItem.FIFO items)
|
||||
{
|
||||
bool flag = _tail == null;
|
||||
QueueItem tail = items._tail;
|
||||
if (tail == null)
|
||||
return false;
|
||||
TransferFromChain(items, items.Head, tail, _tail, false);
|
||||
items._tail = null;
|
||||
_tail = tail;
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void Remove(QueueItem item)
|
||||
{
|
||||
ValidateRemove(item);
|
||||
if (item == _tail)
|
||||
_tail = IsOnlyChild(_tail) ? null : PrevItem(_tail);
|
||||
Unlink(item);
|
||||
}
|
||||
|
||||
public void Advance()
|
||||
{
|
||||
if (_tail == null)
|
||||
return;
|
||||
_tail = NextItem(_tail);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class Stack : QueueItem.Chain
|
||||
{
|
||||
private QueueItem _top;
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
while (_top != null)
|
||||
Pop();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public void Push(QueueItem item)
|
||||
{
|
||||
ValidateAdd(item);
|
||||
Link(item, _top, true);
|
||||
_top = item;
|
||||
}
|
||||
|
||||
public QueueItem Peek() => _top;
|
||||
|
||||
public QueueItem Pop()
|
||||
{
|
||||
QueueItem top = _top;
|
||||
if (top != null)
|
||||
{
|
||||
_top = top._next;
|
||||
if (_top == top)
|
||||
_top = null;
|
||||
Unlink(top);
|
||||
}
|
||||
return top;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Microsoft.Iris.Queues.SimpleQueue
|
||||
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
||||
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
|
||||
// Assembly location: C:\Program Files\Zune\UIX.dll
|
||||
|
||||
namespace Microsoft.Iris.Queues
|
||||
{
|
||||
internal class SimpleQueue : Queue
|
||||
{
|
||||
private QueueItem.FIFO _fifo;
|
||||
|
||||
public SimpleQueue() => _fifo = new QueueItem.FIFO();
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_fifo.Dispose();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public bool IsEmpty => _fifo.Head == null;
|
||||
|
||||
public override QueueItem GetNextItem()
|
||||
{
|
||||
QueueItem head = _fifo.Head;
|
||||
if (head != null)
|
||||
_fifo.Remove(head);
|
||||
return head;
|
||||
}
|
||||
|
||||
public void PostItem(QueueItem item)
|
||||
{
|
||||
if (!_fifo.Append(item))
|
||||
return;
|
||||
OnWake();
|
||||
}
|
||||
|
||||
internal void PostItems(QueueItem.FIFO items)
|
||||
{
|
||||
if (!_fifo.Append(items))
|
||||
return;
|
||||
OnWake();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user