Commit e432b29a authored by Marc Gravell's avatar Marc Gravell

Remove some scenarios where result-boxes are recycled in questionable ways;...

Remove some scenarios where result-boxes are recycled in questionable ways; MULTI isn't fire and forget, so shouldn't be shared
parent a677bac4
...@@ -400,7 +400,7 @@ internal bool UnwrapBox() ...@@ -400,7 +400,7 @@ internal bool UnwrapBox()
{ {
Exception ex; Exception ex;
bool val; bool val;
ResultBox<bool>.UnwrapAndRecycle(resultBox, out val, out ex); ResultBox<bool>.UnwrapAndRecycle(resultBox, false, out val, out ex);
resultBox = null; resultBox = null;
wasSatisfied = ex == null && val; wasSatisfied = ex == null && val;
} }
......
...@@ -2001,7 +2001,7 @@ internal T ExecuteSyncImpl<T>(Message message, ResultProcessor<T> processor, Ser ...@@ -2001,7 +2001,7 @@ internal T ExecuteSyncImpl<T>(Message message, ResultProcessor<T> processor, Ser
// snapshot these so that we can recycle the box // snapshot these so that we can recycle the box
Exception ex; Exception ex;
T val; T val;
ResultBox<T>.UnwrapAndRecycle(source, out val, out ex); // now that we aren't locking it... ResultBox<T>.UnwrapAndRecycle(source, true, out val, out ex); // now that we aren't locking it...
if (ex != null) throw ex; if (ex != null) throw ex;
Trace(message + " received " + val); Trace(message + " received " + val);
return val; return val;
......
...@@ -27,8 +27,7 @@ sealed partial class PhysicalBridge : IDisposable ...@@ -27,8 +27,7 @@ sealed partial class PhysicalBridge : IDisposable
const double ProfileLogSeconds = (ConnectionMultiplexer.MillisecondsPerHeartbeat * ProfileLogSamples) / 1000.0; const double ProfileLogSeconds = (ConnectionMultiplexer.MillisecondsPerHeartbeat * ProfileLogSamples) / 1000.0;
private static readonly Message private static readonly Message ReusableAskingCommand = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.ASKING);
ReusableAskingCommand = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.ASKING);
private readonly CompletionManager completionManager; private readonly CompletionManager completionManager;
readonly long[] profileLog = new long[ProfileLogSamples]; readonly long[] profileLog = new long[ProfileLogSamples];
......
...@@ -2383,7 +2383,7 @@ public bool UnwrapValue(out TimeSpan? value, out Exception ex) ...@@ -2383,7 +2383,7 @@ public bool UnwrapValue(out TimeSpan? value, out Exception ex)
{ {
if (box != null) if (box != null)
{ {
ResultBox<TimeSpan?>.UnwrapAndRecycle(box, out value, out ex); ResultBox<TimeSpan?>.UnwrapAndRecycle(box, false, out value, out ex);
box = null; box = null;
return ex == null; return ex == null;
} }
......
...@@ -177,8 +177,6 @@ class TransactionMessage : Message, IMultiMessage ...@@ -177,8 +177,6 @@ class TransactionMessage : Message, IMultiMessage
static readonly QueuedMessage[] NixMessages = new QueuedMessage[0]; static readonly QueuedMessage[] NixMessages = new QueuedMessage[0];
static readonly Message SharedMulti = Message.Create(-1, CommandFlags.None, RedisCommand.MULTI);
private ConditionResult[] conditions; private ConditionResult[] conditions;
private QueuedMessage[] operations; private QueuedMessage[] operations;
...@@ -276,7 +274,7 @@ public IEnumerable<Message> GetMessages(PhysicalConnection connection) ...@@ -276,7 +274,7 @@ public IEnumerable<Message> GetMessages(PhysicalConnection connection)
if (!IsAborted) if (!IsAborted)
{ {
multiplexer.Trace("Begining transaction"); multiplexer.Trace("Begining transaction");
yield return SharedMulti; yield return Message.Create(-1, CommandFlags.None, RedisCommand.MULTI);
} }
// PART 3: issue the commands // PART 3: issue the commands
......
...@@ -66,7 +66,7 @@ public static ResultBox<T> Get(object stateOrCompletionSource) ...@@ -66,7 +66,7 @@ public static ResultBox<T> Get(object stateOrCompletionSource)
return new ResultBox<T>(stateOrCompletionSource); return new ResultBox<T>(stateOrCompletionSource);
} }
public static void UnwrapAndRecycle(ResultBox<T> box, out T value, out Exception exception) public static void UnwrapAndRecycle(ResultBox<T> box, bool recycle, out T value, out Exception exception)
{ {
if (box == null) if (box == null)
{ {
...@@ -79,12 +79,15 @@ public static void UnwrapAndRecycle(ResultBox<T> box, out T value, out Exception ...@@ -79,12 +79,15 @@ public static void UnwrapAndRecycle(ResultBox<T> box, out T value, out Exception
exception = box.exception; exception = box.exception;
box.value = default(T); box.value = default(T);
box.exception = null; box.exception = null;
if (recycle)
{
for (int i = 0; i < store.Length; i++) for (int i = 0; i < store.Length; i++)
{ {
if (Interlocked.CompareExchange(ref store[i], box, null) == null) return; if (Interlocked.CompareExchange(ref store[i], box, null) == null) return;
} }
} }
} }
}
public void SetResult(T value) public void SetResult(T value)
{ {
...@@ -102,7 +105,7 @@ public override bool TryComplete(bool isAsync) ...@@ -102,7 +105,7 @@ public override bool TryComplete(bool isAsync)
{ {
T val; T val;
Exception ex; Exception ex;
UnwrapAndRecycle(this, out val, out ex); UnwrapAndRecycle(this, true, out val, out ex);
if (ex == null) tcs.TrySetResult(val); if (ex == null) tcs.TrySetResult(val);
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment