Skip to content

Commit

Permalink
Change fix for Apply in SwitchC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jam40jeff committed Feb 2, 2018
1 parent c1b2aa0 commit 523c276
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion c#/src/Sodium/Sodium/Behavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public T Sample() => Transaction.Apply(
internal Lazy<T> SampleLazy(Transaction trans)
{
LazySample s = new LazySample(this);
trans.Last(
trans.Sample(
() =>
{
s.Value = this.valueUpdate.Match(v => v, this.SampleNoTransaction);
Expand Down
48 changes: 24 additions & 24 deletions c#/src/Sodium/Sodium/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class Transaction
private static bool runningOnStartHooks;
private readonly HashSet<Entry> entries = new HashSet<Entry>();
private readonly List<Action<Transaction>> sendQueue = new List<Action<Transaction>>();
private bool finishedPriorityQueue;
private List<Action> sampleQueue = new List<Action>();
private readonly List<Action> lastQueue = new List<Action>();
private readonly Dictionary<int, Action<Transaction>> postQueue = new Dictionary<int, Action<Transaction>>();
internal readonly List<Node.Target> TargetsToActivate;
Expand Down Expand Up @@ -343,19 +343,17 @@ internal void Send(Action<Transaction> action)

internal void Prioritized(Node node, Action<Transaction> action)
{
if (this.finishedPriorityQueue)
Entry e = new Entry(node, action);
lock (Node.NodeRanksLock)
{
this.lastQueue.Add(() => action(this));
}
else
{
Entry e = new Entry(node, action);
lock (Node.NodeRanksLock)
{
this.prioritizedQueue.Enqueue(e, node.Rank);
}
this.entries.Add(e);
this.prioritizedQueue.Enqueue(e, node.Rank);
}
this.entries.Add(e);
}

internal void Sample(Action action)
{
this.sampleQueue.Add(action);
}

/// <summary>
Expand Down Expand Up @@ -439,23 +437,25 @@ internal void Close(bool usingLocal)

this.ReachedClose = true;

this.CheckRegen();

while (true)
do
{
if (this.prioritizedQueue.Count < 1)
while (this.prioritizedQueue.Count > 0)
{
break;
}
this.CheckRegen();

Entry e = this.prioritizedQueue.Dequeue();
this.entries.Remove(e);
e.Action(this);
Entry e = this.prioritizedQueue.Dequeue();
this.entries.Remove(e);
e.Action(this);
}

this.CheckRegen();
List<Action> sq = this.sampleQueue;
this.sampleQueue = new List<Action>();
foreach (Action s in sq)
{
s();
}
}

this.finishedPriorityQueue = true;
while (this.prioritizedQueue.Count > 0);

// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < this.lastQueue.Count; i++)
Expand Down

0 comments on commit 523c276

Please sign in to comment.