Skip to content

Commit

Permalink
reset ownership if handle creation fails (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshmadan authored and badrishc committed Dec 4, 2019
1 parent 312a778 commit d96a164
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cs/src/core/Device/FixedPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FixedPool(int size, Func<T> creator)
{
while (true)
{
for (int i=0; i<size; i++)
for (int i = 0; i < size; i++)
{
if (disposed)
throw new Exception("Disposed");
Expand All @@ -36,7 +36,16 @@ public FixedPool(int size, Func<T> creator)
{
if (Interlocked.CompareExchange(ref owners[i], 2, val) == val)
{
items[i] = creator();
try
{
items[i] = creator();
}
catch
{
Interlocked.Exchange(ref owners[i], val);
throw;
}

return (items[i], i);
}
}
Expand Down

0 comments on commit d96a164

Please sign in to comment.