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