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()
{
Exception ex;
bool val;
ResultBox<bool>.UnwrapAndRecycle(resultBox, out val, out ex);
ResultBox<bool>.UnwrapAndRecycle(resultBox, false, out val, out ex);
resultBox = null;
wasSatisfied = ex == null && val;
}
......
......@@ -2001,7 +2001,7 @@ internal T ExecuteSyncImpl<T>(Message message, ResultProcessor<T> processor, Ser
// snapshot these so that we can recycle the box
Exception ex;
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;
Trace(message + " received " + val);
return val;
......
......@@ -27,8 +27,7 @@ sealed partial class PhysicalBridge : IDisposable
const double ProfileLogSeconds = (ConnectionMultiplexer.MillisecondsPerHeartbeat * ProfileLogSamples) / 1000.0;
private static readonly Message
ReusableAskingCommand = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.ASKING);
private static readonly Message ReusableAskingCommand = Message.Create(-1, CommandFlags.FireAndForget, RedisCommand.ASKING);
private readonly CompletionManager completionManager;
readonly long[] profileLog = new long[ProfileLogSamples];
......
......@@ -2383,7 +2383,7 @@ public bool UnwrapValue(out TimeSpan? value, out Exception ex)
{
if (box != null)
{
ResultBox<TimeSpan?>.UnwrapAndRecycle(box, out value, out ex);
ResultBox<TimeSpan?>.UnwrapAndRecycle(box, false, out value, out ex);
box = null;
return ex == null;
}
......
......@@ -177,8 +177,6 @@ class TransactionMessage : Message, IMultiMessage
static readonly QueuedMessage[] NixMessages = new QueuedMessage[0];
static readonly Message SharedMulti = Message.Create(-1, CommandFlags.None, RedisCommand.MULTI);
private ConditionResult[] conditions;
private QueuedMessage[] operations;
......@@ -276,7 +274,7 @@ public IEnumerable<Message> GetMessages(PhysicalConnection connection)
if (!IsAborted)
{
multiplexer.Trace("Begining transaction");
yield return SharedMulti;
yield return Message.Create(-1, CommandFlags.None, RedisCommand.MULTI);
}
// PART 3: issue the commands
......
......@@ -66,7 +66,7 @@ public static ResultBox<T> Get(object 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)
{
......@@ -79,9 +79,12 @@ public static void UnwrapAndRecycle(ResultBox<T> box, out T value, out Exception
exception = box.exception;
box.value = default(T);
box.exception = null;
for (int i = 0; i < store.Length; i++)
{
if (Interlocked.CompareExchange(ref store[i], box, null) == null) return;
if (recycle)
{
for (int i = 0; i < store.Length; i++)
{
if (Interlocked.CompareExchange(ref store[i], box, null) == null) return;
}
}
}
}
......@@ -102,7 +105,7 @@ public override bool TryComplete(bool isAsync)
{
T val;
Exception ex;
UnwrapAndRecycle(this, out val, out ex);
UnwrapAndRecycle(this, true, out val, out ex);
if (ex == null) tcs.TrySetResult(val);
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