added variable sleep time depending on load an seperate mutex for deleting old items

This was SVN commit r13055.
This commit is contained in:
stwf 2013-01-07 21:02:22 +00:00
parent d29f6c5c49
commit 670deaef2a
4 changed files with 22 additions and 11 deletions

View file

@ -27,6 +27,7 @@
#include "soundmanager/js/AmbientSound.h"
#include "soundmanager/js/MusicSound.h"
#include "soundmanager/js/Sound.h"
#include "lib/external_libraries/libsdl.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "ps/Profiler2.h"
@ -43,7 +44,6 @@ public:
m_DeadItems = new ItemsList;
m_Shutdown = false;
m_Enabled = false;
m_PauseUntilTime = 0;
int ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this);
ENSURE(ret == 0);
@ -102,7 +102,7 @@ public:
void CleanupItems()
{
CScopeLock lock(m_WorkerMutex);
CScopeLock lock(m_DeadItemsMutex);
AL_CHECK
ItemsList::iterator deadItems = m_DeadItems->begin();
while (deadItems != m_DeadItems->end())
@ -114,6 +114,7 @@ public:
}
m_DeadItems->clear();
}
void DeleteItem(long itemNum)
{
CScopeLock lock(m_WorkerMutex);
@ -145,10 +146,6 @@ private:
// Wait until the main thread wakes us up
while ( true )
{
if (timer_Time() < m_PauseUntilTime)
continue;
// Handle shutdown requests as soon as possible
if (GetShutdown())
return;
@ -157,6 +154,7 @@ private:
if (!GetEnabled())
continue;
int pauseTime = 1000;
{
CScopeLock lock(m_WorkerMutex);
@ -167,9 +165,16 @@ private:
while (lstr != m_Items->end()) {
if ((*lstr)->IdleTask())
{
if ( (*lstr)->IsFading() )
pauseTime = 100;
nextItemList->push_back(*lstr);
}
else
{
CScopeLock lock(m_DeadItemsMutex);
m_DeadItems->push_back(*lstr);
}
lstr++;
AL_CHECK
@ -180,7 +185,7 @@ private:
AL_CHECK
}
m_PauseUntilTime = timer_Time() + 0.1;
SDL_Delay( pauseTime );
}
}
@ -202,6 +207,7 @@ private:
// Thread-related members:
pthread_t m_WorkerThread;
CMutex m_WorkerMutex;
CMutex m_DeadItemsMutex;
// Shared by main thread and worker thread:
// These variables are all protected by m_WorkerMutex
@ -210,9 +216,6 @@ private:
bool m_Enabled;
bool m_Shutdown;
// Initialised in constructor by main thread; otherwise used only by worker thread:
double m_PauseUntilTime;
};
void CSoundManager::ScriptingInit()

View file

@ -213,6 +213,12 @@ bool CSoundBase::HandleFade()
return true;
}
bool CSoundBase::IsFading()
{
return ((m_ALSource != 0) && (m_StartFadeTime != 0));
}
bool CSoundBase::GetLooping()
{
return m_Looping;

View file

@ -57,6 +57,7 @@ public:
virtual void SetDirection(const CVector3D& direction);
virtual void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain);
virtual void SetLastPlay(bool last);
virtual bool IsFading();
void Play();
void PlayAndDelete();

View file

@ -38,7 +38,8 @@ public:
virtual CStrW* GetName() = 0;
virtual bool IdleTask() = 0;
virtual bool IsFading() = 0;
virtual void Play() = 0;
virtual void Stop() = 0;