mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-20 19:21:46 +00:00
COMMON: Uplift SafeMutexedSeekableSubReadStream to common
This commit is contained in:
parent
fdccec381d
commit
0adf22278b
@ -581,4 +581,9 @@ WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32 SafeMutexedSeekableSubReadStream::read(void *dataPtr, uint32 dataSize) {
|
||||
Common::StackLock lock(_mutex);
|
||||
return Common::SafeSeekableSubReadStream::read(dataPtr, dataSize);
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
||||
|
@ -22,6 +22,7 @@
|
||||
#ifndef COMMON_SUBSTREAM_H
|
||||
#define COMMON_SUBSTREAM_H
|
||||
|
||||
#include "common/mutex.h"
|
||||
#include "common/ptr.h"
|
||||
#include "common/stream.h"
|
||||
#include "common/types.h"
|
||||
@ -133,6 +134,24 @@ public:
|
||||
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
||||
};
|
||||
|
||||
/**
|
||||
* A special variant of SafeSeekableSubReadStream which locks a mutex during each read.
|
||||
* This is necessary if the music is streamed from disk and it could happen
|
||||
* that a sound effect or another music track is played from the same read stream
|
||||
* while the first music track is updated/read.
|
||||
*/
|
||||
|
||||
class SafeMutexedSeekableSubReadStream : public Common::SafeSeekableSubReadStream {
|
||||
public:
|
||||
SafeMutexedSeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream,
|
||||
Common::Mutex &mutex)
|
||||
: SafeSeekableSubReadStream(parentStream, begin, end, disposeParentStream), _mutex(mutex) {
|
||||
}
|
||||
uint32 read(void *dataPtr, uint32 dataSize) override;
|
||||
protected:
|
||||
Common::Mutex &_mutex;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
} // End of namespace Common
|
||||
|
@ -24,29 +24,6 @@
|
||||
|
||||
namespace Neverhood {
|
||||
|
||||
/**
|
||||
* A special variant of SafeSeekableSubReadStream which locks a mutex during each read.
|
||||
* This is necessary because the music is streamed from disk and it could happen
|
||||
* that a sound effect or another music track is played from the same read stream
|
||||
* while the first music track is updated/read.
|
||||
*/
|
||||
|
||||
class SafeMutexedSeekableSubReadStream : public Common::SafeSeekableSubReadStream {
|
||||
public:
|
||||
SafeMutexedSeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream,
|
||||
Common::Mutex &mutex)
|
||||
: SafeSeekableSubReadStream(parentStream, begin, end, disposeParentStream), _mutex(mutex) {
|
||||
}
|
||||
uint32 read(void *dataPtr, uint32 dataSize) override;
|
||||
protected:
|
||||
Common::Mutex &_mutex;
|
||||
};
|
||||
|
||||
uint32 SafeMutexedSeekableSubReadStream::read(void *dataPtr, uint32 dataSize) {
|
||||
Common::StackLock lock(_mutex);
|
||||
return Common::SafeSeekableSubReadStream::read(dataPtr, dataSize);
|
||||
}
|
||||
|
||||
BlbArchive::BlbArchive() : _extData(nullptr) {
|
||||
}
|
||||
|
||||
@ -158,7 +135,7 @@ Common::SeekableReadStream *BlbArchive::createStream(uint index) {
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *BlbArchive::createStream(BlbArchiveEntry *entry) {
|
||||
return new SafeMutexedSeekableSubReadStream(&_fd, entry->offset, entry->offset + entry->diskSize,
|
||||
return new Common::SafeMutexedSeekableSubReadStream(&_fd, entry->offset, entry->offset + entry->diskSize,
|
||||
DisposeAfterUse::NO, _mutex);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user