Skip to content

Commit

Permalink
Return a ref-counted pooled object back to its pool on Dispose() even…
Browse files Browse the repository at this point in the history
… when the native resource still exists.
  • Loading branch information
JBBee committed Jan 3, 2020
1 parent 2eb2f4e commit 548dc67
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions wrappers/csharp/Intel.RealSense/Base/RefCountedPooledObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ protected override void Dispose(bool disposing)
return;
}

Release(disposing);
m_instance.SetHandleAsInvalid();
bool didDispose = Release(disposing);

//Dispose of this instance even if the underlying resource still exists
if (!didDispose)
{
m_instance.SetHandleAsInvalid();
ObjectPool.Release(this);
}
}

internal void Release(bool disposing)
private bool Release(bool disposing)
{
bool didDispose = false;
var cnt = Thread.VolatileRead(ref refCount.count);
for (; ; )
{
Expand All @@ -70,12 +77,13 @@ internal void Release(bool disposing)
if (u == 0)
{
base.Dispose(disposing);
didDispose = true;
}
break;
}
cnt = b;
}

return didDispose;
}

internal override void Initialize()
Expand Down

0 comments on commit 548dc67

Please sign in to comment.