Refactored mutex use while closing streams in CPortAudioHandle (should fix #320)
This commit is contained in:
1 parent
41cf7a5ac2
commit
4784e57370
1 file changed
+7
-5
@@ -74,13 +74,15 @@ namespace Vocaluxe.Lib.Sound
|
||||
}
|
||||
lock (_Mutex)
|
||||
{
|
||||
if (_Disposed)
|
||||
return;
|
||||
Debug.Assert(_RefCount > 0);
|
||||
_RefCount--;
|
||||
if (_RefCount == 0)
|
||||
PortAudio.Pa_Terminate();
|
||||
}
|
||||
_Disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -99,12 +101,12 @@ namespace Vocaluxe.Lib.Sound
|
||||
public PortAudio.PaError OpenStream(out IntPtr stream, ref PortAudio.PaStreamParameters? inputParameters, ref PortAudio.PaStreamParameters? outputParameters,
|
||||
double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags,
|
||||
PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData)
|
||||
{
|
||||
lock (_Mutex)
|
||||
{
|
||||
if (_Disposed)
|
||||
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
||||
|
||||
lock (_Mutex)
|
||||
{
|
||||
PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback,
|
||||
userData);
|
||||
if (res == PortAudio.PaError.paNoError)
|
||||
@@ -156,12 +158,12 @@ namespace Vocaluxe.Lib.Sound
|
||||
}
|
||||
|
||||
public void CloseStream(IntPtr stream)
|
||||
{
|
||||
lock (_Mutex)
|
||||
{
|
||||
if (_Disposed)
|
||||
throw new ObjectDisposedException("PortAudioHandle already disposed");
|
||||
|
||||
lock (_Mutex)
|
||||
{
|
||||
PortAudio.Pa_CloseStream(stream);
|
||||
_Streams.Remove(stream);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user