mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-13 07:14:59 +00:00
LASTEXPRESS: Use Common::StackLock instead of mutex lock/unlock in Sound class
svn-id: r54247
This commit is contained in:
parent
7d9c43d22b
commit
396bec13f9
@ -133,7 +133,7 @@ SoundManager::~SoundManager() {
|
|||||||
// Timer
|
// Timer
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SoundManager::handleTimer() {
|
void SoundManager::handleTimer() {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i) {
|
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i) {
|
||||||
SoundEntry *entry = (*i);
|
SoundEntry *entry = (*i);
|
||||||
@ -148,8 +148,6 @@ void SoundManager::handleTimer() {
|
|||||||
_soundStream->load(entry->stream);
|
_soundStream->load(entry->stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -164,34 +162,28 @@ void SoundManager::resetQueue(SoundType type1, SoundType type2) {
|
|||||||
if (!type2)
|
if (!type2)
|
||||||
type2 = type1;
|
type2 = type1;
|
||||||
|
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i) {
|
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i) {
|
||||||
if ((*i)->type != type1 && (*i)->type != type2)
|
if ((*i)->type != type1 && (*i)->type != type2)
|
||||||
resetEntry(*i);
|
resetEntry(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::removeFromQueue(EntityIndex entity) {
|
void SoundManager::removeFromQueue(EntityIndex entity) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
SoundEntry *entry = getEntry(entity);
|
SoundEntry *entry = getEntry(entity);
|
||||||
if (entry)
|
if (entry)
|
||||||
resetEntry(entry);
|
resetEntry(entry);
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::removeFromQueue(Common::String filename) {
|
void SoundManager::removeFromQueue(Common::String filename) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
SoundEntry *entry = getEntry(filename);
|
SoundEntry *entry = getEntry(filename);
|
||||||
if (entry)
|
if (entry)
|
||||||
resetEntry(entry);
|
resetEntry(entry);
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::clearQueue() {
|
void SoundManager::clearQueue() {
|
||||||
@ -204,7 +196,7 @@ void SoundManager::clearQueue() {
|
|||||||
|
|
||||||
_flag |= 8;
|
_flag |= 8;
|
||||||
|
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i) {
|
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i) {
|
||||||
SoundEntry *entry = (*i);
|
SoundEntry *entry = (*i);
|
||||||
@ -216,39 +208,30 @@ void SoundManager::clearQueue() {
|
|||||||
i = _cache.reverse_erase(i);
|
i = _cache.reverse_erase(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
|
|
||||||
updateSubtitles();
|
updateSubtitles();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::isBuffered(EntityIndex entity) {
|
bool SoundManager::isBuffered(EntityIndex entity) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
bool buffered = (getEntry(entity) != NULL);
|
return (getEntry(entity) != NULL);
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
|
|
||||||
return buffered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::isBuffered(Common::String filename, bool testForEntity) {
|
bool SoundManager::isBuffered(Common::String filename, bool testForEntity) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
SoundEntry *entry = getEntry(filename);
|
SoundEntry *entry = getEntry(filename);
|
||||||
|
|
||||||
bool ret = (entry != NULL);
|
|
||||||
if (testForEntity)
|
if (testForEntity)
|
||||||
ret = ret && !entry->entity;
|
return entry != NULL && !entry->entity;
|
||||||
|
|
||||||
_mutex.unlock();
|
return (entry != NULL);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Entry
|
// Entry
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SoundManager::setupEntry(SoundEntry *entry, Common::String name, FlagType flag, int a4) {
|
void SoundManager::setupEntry(SoundEntry *entry, Common::String name, FlagType flag, int a4) {
|
||||||
if (!entry)
|
if (!entry)
|
||||||
error("SoundManager::setupEntry: Invalid entry!");
|
error("SoundManager::setupEntry: Invalid entry!");
|
||||||
|
|
||||||
@ -352,12 +335,10 @@ bool SoundManager::setupCache(SoundEntry *entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::clearStatus() {
|
void SoundManager::clearStatus() {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i)
|
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i)
|
||||||
(*i)->status.status |= kSoundStatusClear3;
|
(*i)->status.status |= kSoundStatusClear3;
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::loadSoundData(SoundEntry *entry, Common::String name) {
|
void SoundManager::loadSoundData(SoundEntry *entry, Common::String name) {
|
||||||
@ -450,40 +431,35 @@ void SoundManager::updateEntryState(SoundEntry *entry) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::processEntry(EntityIndex entity) {
|
void SoundManager::processEntry(EntityIndex entity) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
SoundEntry *entry = getEntry(entity);
|
SoundEntry *entry = getEntry(entity);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
updateEntry(entry, 0);
|
updateEntry(entry, 0);
|
||||||
entry->entity = kEntityPlayer;
|
entry->entity = kEntityPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::processEntry(SoundType type) {
|
void SoundManager::processEntry(SoundType type) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
SoundEntry *entry = getEntry(type);
|
SoundEntry *entry = getEntry(type);
|
||||||
if (entry)
|
if (entry)
|
||||||
updateEntry(entry, 0);
|
updateEntry(entry, 0);
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::setupEntry(SoundType type, EntityIndex index) {
|
void SoundManager::setupEntry(SoundType type, EntityIndex index) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
SoundEntry *entry = getEntry(type);
|
SoundEntry *entry = getEntry(type);
|
||||||
if (entry)
|
if (entry)
|
||||||
entry->entity = index;
|
entry->entity = index;
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::processEntry(Common::String filename) {
|
void SoundManager::processEntry(Common::String filename) {
|
||||||
SoundEntry *entry = getEntry(filename);
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
|
SoundEntry *entry = getEntry(filename);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
updateEntry(entry, 0);
|
updateEntry(entry, 0);
|
||||||
entry->entity = kEntityPlayer;
|
entry->entity = kEntityPlayer;
|
||||||
@ -498,16 +474,13 @@ void SoundManager::processEntries() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32 SoundManager::getEntryTime(EntityIndex index) {
|
uint32 SoundManager::getEntryTime(EntityIndex index) {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
uint32 time = 0;
|
|
||||||
SoundEntry *entry = getEntry(index);
|
SoundEntry *entry = getEntry(index);
|
||||||
if (entry)
|
if (entry)
|
||||||
time = entry->time;
|
return entry->time;
|
||||||
|
|
||||||
_mutex.unlock();
|
return 0;
|
||||||
|
|
||||||
return time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -563,7 +536,7 @@ void SoundManager::saveLoadWithSerializer(Common::Serializer &s) {
|
|||||||
uint32 numEntries = count();
|
uint32 numEntries = count();
|
||||||
s.syncAsUint32LE(numEntries);
|
s.syncAsUint32LE(numEntries);
|
||||||
|
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
// Save or load each entry data
|
// Save or load each entry data
|
||||||
if (s.isSaving()) {
|
if (s.isSaving()) {
|
||||||
@ -598,8 +571,6 @@ void SoundManager::saveLoadWithSerializer(Common::Serializer &s) {
|
|||||||
warning("Sound::saveLoadWithSerializer: not implemented!");
|
warning("Sound::saveLoadWithSerializer: not implemented!");
|
||||||
s.skip(numEntries * 64);
|
s.skip(numEntries * 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -607,15 +578,13 @@ void SoundManager::saveLoadWithSerializer(Common::Serializer &s) {
|
|||||||
// as we could have removed an entry between the time we check the count and the time we
|
// as we could have removed an entry between the time we check the count and the time we
|
||||||
// save the entries
|
// save the entries
|
||||||
uint32 SoundManager::count() {
|
uint32 SoundManager::count() {
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
uint32 numEntries = 0;
|
uint32 numEntries = 0;
|
||||||
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i)
|
for (Common::List<SoundEntry *>::iterator i = _cache.begin(); i != _cache.end(); ++i)
|
||||||
if ((*i)->name2.matchString("NISSND?"))
|
if ((*i)->name2.matchString("NISSND?"))
|
||||||
++numEntries;
|
++numEntries;
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
|
|
||||||
return numEntries;
|
return numEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,7 +609,7 @@ void SoundManager::playSound(EntityIndex entity, Common::String filename, FlagTy
|
|||||||
bool SoundManager::playSoundWithSubtitles(Common::String filename, FlagType flag, EntityIndex entity, byte a4) {
|
bool SoundManager::playSoundWithSubtitles(Common::String filename, FlagType flag, EntityIndex entity, byte a4) {
|
||||||
SoundEntry *entry = new SoundEntry();
|
SoundEntry *entry = new SoundEntry();
|
||||||
|
|
||||||
_mutex.lock();
|
Common::StackLock locker(_mutex);
|
||||||
|
|
||||||
setupEntry(entry, filename, flag, 30);
|
setupEntry(entry, filename, flag, 30);
|
||||||
entry->entity = entity;
|
entry->entity = entity;
|
||||||
@ -657,11 +626,7 @@ bool SoundManager::playSoundWithSubtitles(Common::String filename, FlagType flag
|
|||||||
updateEntryState(entry);
|
updateEntryState(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPlaying = (entry->type != kSoundTypeNone);
|
return (entry->type != kSoundTypeNone);
|
||||||
|
|
||||||
_mutex.unlock();
|
|
||||||
|
|
||||||
return isPlaying;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::playSoundEvent(EntityIndex entity, byte action, byte a3) {
|
void SoundManager::playSoundEvent(EntityIndex entity, byte action, byte a3) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user