Skip to content

Commit

Permalink
test tsavorite format
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulusParssinen committed Apr 20, 2024
1 parent 0c2a6aa commit d2abe02
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libs/storage/Tsavorite/cs/src/core/Device/AsyncPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@

namespace Tsavorite.core
{



/// <summary>
/// Asynchronous pool of fixed pre-filled capacity
/// Supports sync get (TryGet) for fast path
/// </summary>
/// <typeparam name="T"></typeparam>
public class AsyncPool<T> : IDisposable where T : IDisposable
public class AsyncPool<T> : IDisposable where T : IDisposable
{
readonly int size;
readonly Func<T> creator;
readonly SemaphoreSlim handleAvailable;
readonly SemaphoreSlim handleAvailable;
readonly ConcurrentQueue<T> itemQueue;

bool disposed = false;
Expand Down Expand Up @@ -45,12 +48,14 @@ public T Get(CancellationToken token = default)
{
for (; ; )
{
if (disposed)
if ( disposed)
throw new TsavoriteException("Getting handle in disposed device");

if (GetOrAdd(itemQueue, out T item))
return item;



handleAvailable.Wait(token);
}
}
Expand Down Expand Up @@ -83,7 +88,7 @@ public bool TryGet(out T item)
{
if (disposed)
{
item = default;
item = default;
return false;
}
return GetOrAdd(itemQueue, out item);
Expand Down

0 comments on commit d2abe02

Please sign in to comment.