Skip to content

Commit dad77db

Browse files
authored
Clear buffers under lock (#526)
1 parent 4201887 commit dad77db

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

BitFaster.Caching/Buffers/MpscBoundedBuffer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ private static int Length(Span<T> output)
254254
/// <summary>
255255
/// Removes all values from the buffer.
256256
/// </summary>
257+
/// <remarks>
258+
/// Clear must be called from the single consumer thread.
259+
/// </remarks>
257260
public void Clear()
258261
{
259262
while (TryTake(out _) != BufferStatus.Empty)

BitFaster.Caching/Buffers/StripedMpscBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public BufferStatus TryAdd(T item)
123123
/// Removes all values from the buffer.
124124
/// </summary>
125125
/// <remarks>
126-
/// Not thread safe.
126+
/// Clear must be called from the single consumer thread.
127127
/// </remarks>
128128
public void Clear()
129129
{

BitFaster.Caching/Lfu/ConcurrentLfuCore.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,10 @@ public void Clear()
137137
{
138138
this.Trim(this.Count);
139139

140-
this.readBuffer.Clear();
141-
this.writeBuffer.Clear();
142-
143140
lock (maintenanceLock)
144141
{
142+
this.readBuffer.Clear();
143+
this.writeBuffer.Clear();
145144
this.cmSketch.Clear();
146145
}
147146
}

0 commit comments

Comments
 (0)