Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions BitFaster.Caching/Buffers/MpmcBoundedBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BitFaster.Caching.Buffers
/// Based on the Segment internal class from the .NET ConcurrentQueue class.
public sealed class MpmcBoundedBuffer<T>
{
private readonly Slot[] slots;
private Slot[] slots;
private readonly int slotsMask;
private PaddedHeadAndTail headAndTail; // mutable struct, don't mark readonly

Expand Down Expand Up @@ -208,11 +208,13 @@ public BufferStatus TryAdd(T item)
/// <summary>
/// Removes all values from the buffer.
/// </summary>
/// <remarks>
/// Not thread safe.
/// </remarks>
public void Clear()
{
while (TryTake(out _) != BufferStatus.Empty)
{
}
slots = new Slot[slots.Length];
headAndTail = new PaddedHeadAndTail();
}

[StructLayout(LayoutKind.Auto)]
Expand Down
10 changes: 6 additions & 4 deletions BitFaster.Caching/Buffers/MpscBoundedBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace BitFaster.Caching.Buffers
[DebuggerDisplay("Count = {Count}/{Capacity}")]
public sealed class MpscBoundedBuffer<T> where T : class
{
private readonly T[] buffer;
private T[] buffer;
private readonly int mask;
private PaddedHeadAndTail headAndTail; // mutable struct, don't mark readonly

Expand Down Expand Up @@ -254,11 +254,13 @@ private static int Length(Span<T> output)
/// <summary>
/// Removes all values from the buffer.
/// </summary>
/// <remarks>
/// Not thread safe.
/// </remarks>
public void Clear()
{
while (TryTake(out _) != BufferStatus.Empty)
{
}
buffer = new T[buffer.Length];
headAndTail = new PaddedHeadAndTail();
}
}
}
5 changes: 2 additions & 3 deletions BitFaster.Caching/Lfu/ConcurrentLfuCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ public void Clear()
{
this.Trim(this.Count);

this.readBuffer.Clear();
this.writeBuffer.Clear();

lock (maintenanceLock)
{
this.cmSketch.Clear();
this.readBuffer.Clear();
this.writeBuffer.Clear();
}
}

Expand Down