# HG changeset patch # User Denis Lila # Date 1308237095 14400 # Node ID 26295314f6d60fc8e3676097cd8bbcded34e62b9 # Parent cc35d8ed9124f5451288fa59db5eca44e2a865af PR1741: Fix a few concurrency problems in pulse audio. 2011-06-16 Denis Lila * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java (addStreamListeners): Remove this.notifyAll() from openCloseListener.update; change this.notifyAll() to PulseAudioDataLine.this.notifyAll() in startedListener.update. * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java (read): Put fragmentBuffer null check in the synchronized block. (flush): Make it synchronized to avoid race condition with read(). diff -r cc35d8ed9124 -r 26295314f6d6 ChangeLog --- a/ChangeLog Fri Jun 17 16:16:47 2011 -0400 +++ b/ChangeLog Thu Jun 16 11:11:35 2011 -0400 @@ -1,3 +1,13 @@ +2011-06-16 Denis Lila + + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java + (addStreamListeners): Remove this.notifyAll() from + openCloseListener.update; change this.notifyAll() to + PulseAudioDataLine.this.notifyAll() in startedListener.update. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java + (read): Put fragmentBuffer null check in the synchronized block. + (flush): Make it synchronized to avoid race condition with read(). + 2011-06-17 Denis Lila * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java diff -r cc35d8ed9124 -r 26295314f6d6 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Jun 17 16:16:47 2011 -0400 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Thu Jun 16 11:11:35 2011 -0400 @@ -185,11 +185,7 @@ PulseAudioDataLine.this, LineEvent.Type.CLOSE, framesSinceOpen))); } - synchronized (this) { - this.notifyAll(); - } semaphore.release(); - } } } @@ -217,7 +213,7 @@ fireLineEvent(new LineEvent(PulseAudioDataLine.this, LineEvent.Type.START, framesSinceOpen)); synchronized (this) { - this.notifyAll(); + PulseAudioDataLine.this.notifyAll(); } } dataWritten = true; diff -r cc35d8ed9124 -r 26295314f6d6 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Jun 17 16:16:47 2011 -0400 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Thu Jun 16 11:11:35 2011 -0400 @@ -184,9 +184,8 @@ */ /* on first read() of the line, fragmentBuffer is null */ - if (fragmentBuffer != null) { - synchronized (this) { - + synchronized (this) { + if (fragmentBuffer != null) { boolean fragmentBufferSmaller = fragmentBuffer.length < length; int smallerBufferLength = Math.min(fragmentBuffer.length, length); @@ -215,7 +214,6 @@ position += bytesRead; remainingLength -= bytesRead; fragmentBuffer = null; - } } @@ -315,11 +313,10 @@ synchronized (this) { drained = true; } - } @Override - public void flush() { + public synchronized void flush() { if (isOpen()) { /* flush the buffer on pulseaudio's side */ @@ -331,11 +328,9 @@ operation.releaseReference(); } - synchronized (this) { - flushed = true; - /* flush the partial fragment we stored */ - fragmentBuffer = null; - } + flushed = true; + /* flush the partial fragment we stored */ + fragmentBuffer = null; } @Override