mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-24 03:39:43 +00:00
Use a condition variable to wake up the audio stream thread
This should make starting streams a bit more responsive, and allows us to do more in it that really shouldn't wait for its next wake up.
This commit is contained in:
parent
4a078725d4
commit
9568aa6a84
1 changed files with 8 additions and 4 deletions
|
@ -217,6 +217,7 @@ struct OpenAL_Output::StreamThread {
|
||||||
typedef std::vector<OpenAL_SoundStream*> StreamVec;
|
typedef std::vector<OpenAL_SoundStream*> StreamVec;
|
||||||
StreamVec mStreams;
|
StreamVec mStreams;
|
||||||
boost::recursive_mutex mMutex;
|
boost::recursive_mutex mMutex;
|
||||||
|
boost::condition_variable_any mCondVar;
|
||||||
boost::thread mThread;
|
boost::thread mThread;
|
||||||
|
|
||||||
StreamThread()
|
StreamThread()
|
||||||
|
@ -231,9 +232,9 @@ struct OpenAL_Output::StreamThread {
|
||||||
// boost::thread entry point
|
// boost::thread entry point
|
||||||
void operator()()
|
void operator()()
|
||||||
{
|
{
|
||||||
|
boost::unique_lock<boost::recursive_mutex> lock(mMutex);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> lock(mMutex);
|
|
||||||
StreamVec::iterator iter = mStreams.begin();
|
StreamVec::iterator iter = mStreams.begin();
|
||||||
while(iter != mStreams.end())
|
while(iter != mStreams.end())
|
||||||
{
|
{
|
||||||
|
@ -242,16 +243,19 @@ struct OpenAL_Output::StreamThread {
|
||||||
else
|
else
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
lock.unlock();
|
mCondVar.timed_wait(lock, boost::posix_time::milliseconds(50));
|
||||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(OpenAL_SoundStream *stream)
|
void add(OpenAL_SoundStream *stream)
|
||||||
{
|
{
|
||||||
boost::lock_guard<boost::recursive_mutex> lock(mMutex);
|
boost::unique_lock<boost::recursive_mutex> lock(mMutex);
|
||||||
if(std::find(mStreams.begin(), mStreams.end(), stream) == mStreams.end())
|
if(std::find(mStreams.begin(), mStreams.end(), stream) == mStreams.end())
|
||||||
|
{
|
||||||
mStreams.push_back(stream);
|
mStreams.push_back(stream);
|
||||||
|
lock.unlock();
|
||||||
|
mCondVar.notify_all();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(OpenAL_SoundStream *stream)
|
void remove(OpenAL_SoundStream *stream)
|
||||||
|
|
Loading…
Reference in a new issue