1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 19:29:09 +00:00

Replace hsMutex with std::mutex

This commit is contained in:
2014-04-05 20:45:58 -07:00
parent 964256411e
commit 2947acb2c8
16 changed files with 166 additions and 342 deletions

View File

@ -90,12 +90,13 @@ hsError plSoundPreloader::Run()
while (fRunning)
{
fCritSect.Lock();
while (fBuffers.GetCount())
{
templist.Append(fBuffers.Pop());
std::lock_guard<std::mutex> lock(fCritSect);
while (fBuffers.GetCount())
{
templist.Append(fBuffers.Pop());
}
}
fCritSect.Unlock();
if (templist.GetCount() == 0)
{
@ -130,14 +131,15 @@ hsError plSoundPreloader::Run()
}
// we need to be sure that all buffers are removed from our load list when shutting this thread down or we will hang,
// since the sound buffer will wait to be destroyed until it is marked as loaded
fCritSect.Lock();
while (fBuffers.GetCount())
// since the sound buffer will wait to be destroyed until it is marked as loaded
{
plSoundBuffer* buf = fBuffers.Pop();
buf->SetLoaded(true);
std::lock_guard<std::mutex> lock(fCritSect);
while (fBuffers.GetCount())
{
plSoundBuffer* buf = fBuffers.Pop();
buf->SetLoaded(true);
}
}
fCritSect.Unlock();
return hsOK;
}

View File

@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAudioFileReader.h"
#include "hsThread.h"
#include "plFileSystem.h"
#include <mutex>
//// Class Definition ////////////////////////////////////////////////////////
@ -165,7 +166,7 @@ protected:
hsTArray<plSoundBuffer*> fBuffers;
hsEvent fEvent;
bool fRunning;
hsMutex fCritSect;
std::mutex fCritSect;
public:
virtual hsError Run();
@ -184,9 +185,10 @@ public:
bool IsRunning() const { return fRunning; }
void AddBuffer(plSoundBuffer* buffer) {
fCritSect.Lock();
fBuffers.Push(buffer);
fCritSect.Unlock();
{
std::lock_guard<std::mutex> lock(fCritSect);
fBuffers.Push(buffer);
}
fEvent.Signal();
}