|
From: Johnny O. <js...@us...> - 2010-10-28 20:45:58
|
Module: performous
Branch: opengl2
Commit: 92d9832b10425a7914d764fe2fd92842ad653864
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Oct 23 17:27:33 2010 +0200
Add hang protection/handling in portaudio.hpp.
---
game/libda/portaudio.hpp | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/game/libda/portaudio.hpp b/game/libda/portaudio.hpp
index a298173..b4d512d 100644
--- a/game/libda/portaudio.hpp
+++ b/game/libda/portaudio.hpp
@@ -4,6 +4,7 @@
* @file portaudio.hpp OOP / RAII wrappers & utilities for PortAudio library.
*/
+#include <boost/thread.hpp>
#include <portaudio.h>
#include <cstdlib>
#include <stdexcept>
@@ -69,7 +70,14 @@ namespace portaudio {
struct Init {
Init() { PORTAUDIO_CHECKED(Pa_Initialize, ()); }
- ~Init() { std::cout << "Pa_Terminate..."; std::cout.flush(); Pa_Terminate(); std::cout << "ok" << std::endl; }
+ ~Init() {
+ // Give audio a little time to shutdown but then just quit
+ boost::thread audiokiller(Pa_Terminate);
+ if (!audiokiller.timed_join(boost::posix_time::milliseconds(2000))) {
+ std::cout << "PortAudio BUG: Pa_Terminate hung for more than two seconds. Exiting program." << std::endl;
+ exit(1);
+ }
+ }
};
struct Params {
@@ -114,7 +122,14 @@ namespace portaudio {
{
PORTAUDIO_CHECKED(Pa_OpenStream, (&m_handle, input, output, sampleRate, framesPerBuffer, flags, functorCallback<Functor>, &functor));
}
- ~Stream() { Pa_CloseStream(m_handle); }
+ ~Stream() {
+ // Give audio a little time to shutdown but then just quit
+ boost::thread audiokiller(Pa_CloseStream, m_handle);
+ if (!audiokiller.timed_join(boost::posix_time::milliseconds(2000))) {
+ std::cout << "PortAudio BUG: Pa_CloseStream hung for more than two seconds. Exiting program." << std::endl;
+ exit(1);
+ }
+ }
operator PaStream*() { return m_handle; }
};
|