Browse Source

added rude's better SDL thread fix

bill@Ixion 16 years ago
parent
commit
2abd9c1141
2 changed files with 11 additions and 7 deletions
  1. 6 7
      src/modules/audio/openal/Audio.cpp
  2. 5 0
      src/modules/audio/openal/Audio.h

+ 6 - 7
src/modules/audio/openal/Audio.cpp

@@ -27,6 +27,7 @@ namespace audio
 namespace openal
 {
 	Audio::Audio()
+		: finish(false)
 	{
 		// Passing zero for default device.
 		device = alcOpenDevice(0);
@@ -52,7 +53,10 @@ namespace openal
 
 	Audio::~Audio()
 	{
-		//SDL_KillThread(thread);
+		finish = true;
+
+		int status;
+		SDL_WaitThread(thread, &status);
 
 		pool->stop();
 
@@ -61,18 +65,13 @@ namespace openal
 		alcMakeContextCurrent(0);
 		alcDestroyContext(context);
 		alcCloseDevice(device);
-		
-		printf("waiting on thread to finish...\n");
-		int status;
-		SDL_WaitThread(thread, &status);
-		printf("%d", status);
 	}
 
 	int Audio::run(void * d)
 	{
 		Audio * instance = (Audio*)d;
 		
-		while(true)
+		while(!instance->finish)
 		{
 			instance->pool->update();
 			SDL_Delay(10);

+ 5 - 0
src/modules/audio/openal/Audio.h

@@ -70,6 +70,11 @@ namespace openal
 		// The 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);
 
 	public: