added rude's better SDL thread fix

This commit is contained in:
bill@Ixion
2009-08-26 17:48:29 -05:00
2 changed files with 11 additions and 7 deletions
+6 -7
View File
@@ -27,6 +27,7 @@ namespace audio
namespace openal namespace openal
{ {
Audio::Audio() Audio::Audio()
: finish(false)
{ {
// Passing zero for default device. // Passing zero for default device.
device = alcOpenDevice(0); device = alcOpenDevice(0);
@@ -52,7 +53,10 @@ namespace openal
Audio::~Audio() Audio::~Audio()
{ {
//SDL_KillThread(thread); finish = true;
int status;
SDL_WaitThread(thread, &status);
pool->stop(); pool->stop();
@@ -61,18 +65,13 @@ namespace openal
alcMakeContextCurrent(0); alcMakeContextCurrent(0);
alcDestroyContext(context); alcDestroyContext(context);
alcCloseDevice(device); alcCloseDevice(device);
printf("waiting on thread to finish...\n");
int status;
SDL_WaitThread(thread, &status);
printf("%d", status);
} }
int Audio::run(void * d) int Audio::run(void * d)
{ {
Audio * instance = (Audio*)d; Audio * instance = (Audio*)d;
while(true) while(!instance->finish)
{ {
instance->pool->update(); instance->pool->update();
SDL_Delay(10); SDL_Delay(10);
+5
View File
@@ -70,6 +70,11 @@ namespace openal
// The Pool. // The Pool.
Pool * pool; Pool * pool;
// Set this to true when the thread should finish.
// Main thread will write to this value, and Audio::run
// will read from it.
bool finish;
static int run(void * unused); static int run(void * unused);
public: public: