mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
bg audio: Sprinkle on some thread safety
This commit is contained in:
parent
f8e32f4a71
commit
3b4e30d50f
@ -1,6 +1,7 @@
|
||||
#include <string>
|
||||
#include "base/logging.h"
|
||||
#include "base/timeutil.h"
|
||||
#include "base/mutex.h"
|
||||
#include "native/file/chunk_file.h"
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -142,17 +143,21 @@ private:
|
||||
SimpleAudio *decoder_;
|
||||
};
|
||||
|
||||
static recursive_mutex bgMutex;
|
||||
static std::string bgGamePath;
|
||||
static int playbackOffset;
|
||||
static AT3PlusReader *at3Reader;
|
||||
static double gameLastChanged;
|
||||
|
||||
void SetBackgroundAudioGame(const std::string &path) {
|
||||
time_update();
|
||||
|
||||
lock_guard lock(bgMutex);
|
||||
if (path == bgGamePath) {
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
time_update();
|
||||
|
||||
gameLastChanged = time_now_d();
|
||||
if (at3Reader) {
|
||||
at3Reader->Shutdown();
|
||||
@ -165,6 +170,8 @@ void SetBackgroundAudioGame(const std::string &path) {
|
||||
|
||||
int MixBackgroundAudio(short *buffer, int size) {
|
||||
time_update();
|
||||
|
||||
lock_guard lock(bgMutex);
|
||||
// If there's a game, and some time has passed since the selected game
|
||||
// last changed... (to prevent crazy amount of reads when skipping through a list)
|
||||
if (!at3Reader && bgGamePath.size() && (time_now_d() - gameLastChanged > 0.5)) {
|
||||
|
Loading…
Reference in New Issue
Block a user