Fix for issue #441 Audio Recording Stops After Encountering Error (#449)

* Fix for issue #441.
Method doc reads that the method is thread-safe, but there exist no locking to ensure thread safety on call into recycle method. Modifying the decrementUserCount method to block other callers to ensure thread-safe access.

This appears to be a hot area of code and there may be a performance hit by doing this, please double check my work here.

* Moving synchronized to recycle method as it's accessed by two different methods that could potentially cause an unsafe access race condition.

* Revert - synchronizing recycle does not protect against multiple recycle calls on the same object.
This commit is contained in:
whelgeson
2018-12-16 18:12:41 -06:00
committed by Denny Sheirer
parent 72fe72c833
commit 735fca16d6

View File

@@ -93,7 +93,7 @@ public abstract class AbstractReusableBuffer
*
* This method is thread-safe.
*/
public void decrementUserCount()
public synchronized void decrementUserCount()
{
if(mUserCount.decrementAndGet() <= 0)
{
@@ -104,7 +104,7 @@ public abstract class AbstractReusableBuffer
/**
* Sends this buffer back to the owning buffer queue for reuse
*/
private void recycle()
private synchronized void recycle()
{
prepareForRecycle();