Use Environment.NewLine and Environment.StackTrace

This commit is contained in:
Ben Adams 2016-07-20 22:28:47 +01:00
parent 7b8abf5a3e
commit aa385a1317
2 changed files with 8 additions and 13 deletions

View File

@ -61,6 +61,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
/// </summary>
private bool _disposedValue = false; // To detect redundant calls
/// <summary>
/// Called to take a block from the pool.
/// </summary>
/// <returns>The block that is reserved for the called. It must be passed to Return when it is no longer being used.</returns>
#if DEBUG
public MemoryPoolBlock Lease([CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
@ -68,11 +72,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{
Debug.Assert(!_disposedValue, "Block being leased from disposed pool!");
#else
/// <summary>
/// Called to take a block from the pool.
/// </summary>
/// <returns>The block that is reserved for the called. It must be passed to Return when it is no longer being used.</returns>
public MemoryPoolBlock Lease()
{
#endif
@ -83,9 +82,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
#if DEBUG
block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber;
block.IsLeased = true;
#if !NETSTANDARD1_3
block.StackTrace = new StackTrace(true).ToString();
#endif
block.StackTrace = Environment.StackTrace;
#endif
return block;
}
@ -94,9 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
#if DEBUG
block.Leaser = memberName + ", " + sourceFilePath + ", " + sourceLineNumber;
block.IsLeased = true;
#if !NETSTANDARD1_3
block.StackTrace = new StackTrace(true).ToString();
#endif
block.StackTrace = Environment.StackTrace;
#endif
return block;
}
@ -153,7 +148,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{
#if DEBUG
Debug.Assert(block.Pool == this, "Returned block was not leased from this pool");
Debug.Assert(block.IsLeased, "Block being returned to pool twice: " + block.Leaser + "\n" + block.StackTrace);
Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}{block.StackTrace}");
block.IsLeased = false;
#endif

View File

@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
~MemoryPoolBlock()
{
#if DEBUG
Debug.Assert(Slab == null || !Slab.IsActive, "Block being garbage collected instead of returned to pool: " + Leaser + "\n" + StackTrace);
Debug.Assert(Slab == null || !Slab.IsActive, $"{Environment.NewLine}{Environment.NewLine}*** Block being garbage collected instead of returned to pool: {Leaser} ***{Environment.NewLine}Allocation StackTrace:{Environment.NewLine}{StackTrace}");
#endif
if (Slab != null && Slab.IsActive)
{