From 735fca16d6afcc40e86ad632ce57670bac636e53 Mon Sep 17 00:00:00 2001 From: whelgeson Date: Sun, 16 Dec 2018 18:12:41 -0600 Subject: [PATCH] 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. --- .../github/dsheirer/sample/buffer/AbstractReusableBuffer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/dsheirer/sample/buffer/AbstractReusableBuffer.java b/src/main/java/io/github/dsheirer/sample/buffer/AbstractReusableBuffer.java index 77fbaf2e..c7085f3d 100644 --- a/src/main/java/io/github/dsheirer/sample/buffer/AbstractReusableBuffer.java +++ b/src/main/java/io/github/dsheirer/sample/buffer/AbstractReusableBuffer.java @@ -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();