Skip to content

Commit

Permalink
fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wsm2110 committed Jul 11, 2024
1 parent cd74732 commit 0cb4c49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Concurrent/CMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ public bool Update(TKey key, TValue newValue, TValue comparisonValue)
} while (true); // Continue probing until a matching entry is found or the table is exhausted
}


/// <summary>
/// This method demonstrates a sophisticated approach to updating values in a concurrent hash table, leveraging quadratic probing, atomic operations, and handle the ABA problem effectively.
/// The use of aggressive inlining and careful memory management ensures that the method performs efficiently even under high concurrency.
Expand Down Expand Up @@ -578,7 +577,7 @@ public bool Remove(TKey key, out TValue value)

// Release the lock
entry.Exit();
// Interlocked.Decrement(ref _counter);
_counter.Decrement();
return true;
}

Expand Down Expand Up @@ -619,7 +618,7 @@ public void Clear()
{
var table = new Table(_table.Length, _loadFactor);
Interlocked.Exchange(ref _table, table);
// Interlocked.Exchange(ref _counter, 0);
Interlocked.Exchange(ref _counter, new ThreadLocalCounter());
}

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Concurrent/ThreadLocalCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public long Sum()
return sum;
}

internal void Decrement()
{
threadLocalCell.Value.Decrement();
}

private class Cell
{
private int value;
Expand All @@ -41,6 +46,11 @@ public void Increment()
Interlocked.Increment(ref value);
}

public void Decrement()
{
Interlocked.Decrement(ref value);
}

public long Get()
{
return value;
Expand Down

0 comments on commit 0cb4c49

Please sign in to comment.