Skip to content

Commit

Permalink
Remove unused useHandlesForPin (#465)
Browse files Browse the repository at this point in the history
* remove unused useHandlesForPin

* remove gchandle
  • Loading branch information
vazois committed Jun 14, 2024
1 parent 92f4274 commit 7d00ab9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 41 deletions.
6 changes: 2 additions & 4 deletions libs/common/Memory/LimitedFixedBufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public sealed class LimitedFixedBufferPool : IDisposable
{
readonly PoolLevel[] pool;
readonly int numLevels, minAllocationSize, maxEntriesPerLevel;
readonly bool useHandlesForPin;
readonly ILogger logger;

/// <summary>
Expand All @@ -33,12 +32,11 @@ public sealed class LimitedFixedBufferPool : IDisposable
/// <summary>
/// Constructor
/// </summary>
public LimitedFixedBufferPool(int minAllocationSize, int maxEntriesPerLevel = 16, int numLevels = 4, bool useHandlesForPin = false, ILogger logger = null)
public LimitedFixedBufferPool(int minAllocationSize, int maxEntriesPerLevel = 16, int numLevels = 4, ILogger logger = null)
{
this.minAllocationSize = minAllocationSize;
this.maxEntriesPerLevel = maxEntriesPerLevel;
this.numLevels = numLevels;
this.useHandlesForPin = useHandlesForPin;
this.logger = logger;
pool = new PoolLevel[numLevels];
}
Expand Down Expand Up @@ -97,7 +95,7 @@ public unsafe PoolEntry Get(int size)
return page;
}
}
return new PoolEntry(size, this, useHandlesForPin);
return new PoolEntry(size, this);
}

/// <summary>
Expand Down
40 changes: 3 additions & 37 deletions libs/common/Memory/PoolEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Garnet.common
{
Expand All @@ -23,38 +22,26 @@ public unsafe class PoolEntry : IDisposable
/// </summary>
public byte* entryPtr;

readonly bool useHandlesForPin;
GCHandle handle;
readonly LimitedFixedBufferPool pool;
bool disposed;

/// <summary>
/// Constructor
/// </summary>
public PoolEntry(int size, LimitedFixedBufferPool pool, bool useHandlesForPin = false)
public PoolEntry(int size, LimitedFixedBufferPool pool)
{
Debug.Assert(pool != null);
this.pool = pool;
this.useHandlesForPin = useHandlesForPin;
this.disposed = false;
if (useHandlesForPin)
{
entry = new byte[size];
Pin();
}
else
{
entry = GC.AllocateArray<byte>(size, pinned: true);
entryPtr = (byte*)Unsafe.AsPointer(ref entry[0]);
}
entry = GC.AllocateArray<byte>(size, pinned: true);
entryPtr = (byte*)Unsafe.AsPointer(ref entry[0]);
}

/// <inheritdoc />
public void Dispose()
{
Debug.Assert(!disposed);
disposed = true;
Unpin();
pool.Return(this);
}

Expand All @@ -65,27 +52,6 @@ public void Reuse()
{
Debug.Assert(disposed);
disposed = false;
Pin();
}

/// <summary>
/// Pin
/// </summary>
void Pin()
{
if (useHandlesForPin)
{
handle = GCHandle.Alloc(entry, GCHandleType.Pinned);
entryPtr = (byte*)handle.AddrOfPinnedObject();
}
}

/// <summary>
/// Unpin
/// </summary>
void Unpin()
{
if (useHandlesForPin) handle.Free();
}
}
}

0 comments on commit 7d00ab9

Please sign in to comment.