mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +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;
|
||||
StreamVec mStreams;
|
||||
boost::recursive_mutex mMutex;
|
||||
boost::condition_variable_any mCondVar;
|
||||
boost::thread mThread;
|
||||
|
||||
StreamThread()
|
||||
|
@ -231,9 +232,9 @@ struct OpenAL_Output::StreamThread {
|
|||
// boost::thread entry point
|
||||
void operator()()
|
||||
{
|
||||
boost::unique_lock<boost::recursive_mutex> lock(mMutex);
|
||||
while(1)
|
||||
{
|
||||
boost::unique_lock<boost::recursive_mutex> lock(mMutex);
|
||||
StreamVec::iterator iter = mStreams.begin();
|
||||
while(iter != mStreams.end())
|
||||
{
|
||||
|
@ -242,16 +243,19 @@ struct OpenAL_Output::StreamThread {
|
|||
else
|
||||
++iter;
|
||||
}
|
||||
lock.unlock();
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
|
||||
mCondVar.timed_wait(lock, boost::posix_time::milliseconds(50));
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
mStreams.push_back(stream);
|
||||
lock.unlock();
|
||||
mCondVar.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void remove(OpenAL_SoundStream *stream)
|
||||
|
|
Loading…
Reference in a new issue