1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-09 07:51:28 +00:00

Add a thread pool for background job processing, and use it for OggDecoder.

The pool adjusts to the amount of required threads.
The implementation is as simple as possible, but should be enough
for future extensions.

This brings down decoder thread creation/destruction even more.

Also fix OpenALSystem::release() to close channels properly on shutdown,
otherwise it would deadlock with the pool, because it waits until all
threads have died off, which did not necessarily happen.
This commit is contained in:
fgenesis 2012-02-09 16:08:35 +01:00
commit 010f44d264
5 changed files with 460 additions and 8 deletions

View file

@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Base.h"
#include "Core.h"
#include "MT.h"
#include "FmodOpenALBridge.h"
@ -108,7 +109,7 @@ private:
int freq;
#ifdef BBGE_BUILD_SDL
SDL_Thread *thread;
Runnable *thread;
#else
#warning Threads not supported, music may cut out on area changes!
// ... because the stream runs out of decoded data while the area is
@ -282,11 +283,12 @@ bool OggDecoder::start(ALuint source, bool loop)
#ifdef BBGE_BUILD_SDL
stop_thread = false;
thread = SDL_CreateThread((int (*)(void *))decode_loop, this);
if (!thread)
thread = new FunctionRunnable(false, (void (*)(void *))decode_loop, this);
if (!core->threadpool.addJob(thread))
{
debugLog("Failed to create Ogg Vorbis decode thread: "
+ std::string(SDL_GetError()));
delete thread;
thread = NULL;
debugLog("Failed to add Ogg Vorbis decoder to thread pool");
}
#endif
@ -322,7 +324,8 @@ void OggDecoder::stop()
if (thread)
{
stop_thread = true;
SDL_WaitThread(thread, NULL);
thread->wait();
delete thread;
thread = NULL;
}
#endif
@ -1313,10 +1316,9 @@ FMOD_RESULT OpenALSystem::release()
for (int i = 0; i < num_channels; i++)
{
const ALuint sid = channels[i].getSourceName();
channels[i].stop();
channels[i].setSourceName(0);
channels[i].setSound(NULL);
alSourceStop(sid);
alSourcei(sid, AL_BUFFER, 0);
alDeleteSources(1, &sid);
}
ALCdevice *dev = alcGetContextsDevice(ctx);