mirror of
https://github.com/wiiu-env/launchiine.git
synced 2024-11-22 01:39:18 +01:00
Add a mutex for accessing the GameList
This commit is contained in:
parent
25a0aa54e7
commit
340baed8ed
@ -16,6 +16,7 @@
|
||||
#include "system/CMutex.h"
|
||||
|
||||
void GameList::clear() {
|
||||
lock();
|
||||
for (auto const& x : fullGameList) {
|
||||
if(x != NULL) {
|
||||
if(x->imageData != NULL) {
|
||||
@ -31,6 +32,8 @@ void GameList::clear() {
|
||||
//! Clear memory of the vector completely
|
||||
std::vector<gameInfo *>().swap(filteredList);
|
||||
std::vector<gameInfo*>().swap(fullGameList);
|
||||
|
||||
unlock();
|
||||
titleListChanged(this);
|
||||
}
|
||||
|
||||
@ -90,6 +93,7 @@ int32_t GameList::readGameList() {
|
||||
newGameInfo->name = "<unknown>";
|
||||
newGameInfo->imageData = NULL;
|
||||
DCFlushRange(newGameInfo, sizeof(gameInfo));
|
||||
|
||||
fullGameList.push_back(newGameInfo);
|
||||
titleAdded(newGameInfo);
|
||||
cnt++;
|
||||
@ -184,6 +188,7 @@ void GameList::internalFilterList(std::vector<gameInfo*> &fullList) {
|
||||
}
|
||||
|
||||
int32_t GameList::filterList(const char * filter) {
|
||||
lock();
|
||||
if(filter) {
|
||||
gameFilter = filter;
|
||||
}
|
||||
@ -202,8 +207,9 @@ int32_t GameList::filterList(const char * filter) {
|
||||
titleListChanged(this);
|
||||
|
||||
AsyncExecutor::execute([&] { updateTitleInfo();});
|
||||
|
||||
return filteredList.size();
|
||||
int32_t res = filteredList.size();
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
|
||||
@ -215,6 +221,7 @@ void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
|
||||
}
|
||||
|
||||
int32_t GameList::loadUnfiltered() {
|
||||
lock();
|
||||
if(fullGameList.size() == 0) {
|
||||
readGameList();
|
||||
}
|
||||
@ -231,11 +238,15 @@ int32_t GameList::loadUnfiltered() {
|
||||
|
||||
titleListChanged(this);
|
||||
|
||||
return filteredList.size();
|
||||
int res = filteredList.size();
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
void GameList::sortList() {
|
||||
lock();
|
||||
std::sort(filteredList.begin(), filteredList.end(), nameSortCallback);
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool GameList::nameSortCallback(const gameInfo *a, const gameInfo *b) {
|
||||
|
@ -17,24 +17,36 @@ typedef struct _gameInfo {
|
||||
class GameList {
|
||||
public:
|
||||
GameList() : selectedGame(0) { };
|
||||
~GameList() { clear(); };
|
||||
~GameList() {
|
||||
clear();
|
||||
};
|
||||
|
||||
int32_t size() const {
|
||||
return filteredList.size();
|
||||
int32_t size() {
|
||||
lock();
|
||||
int32_t res = filteredList.size();
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
int32_t gameCount() const {
|
||||
return fullGameList.size();
|
||||
int32_t gameCount() {
|
||||
lock();
|
||||
int32_t res = fullGameList.size();
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
int32_t filterList(const char * gameFilter = NULL);
|
||||
int32_t loadUnfiltered();
|
||||
|
||||
gameInfo * at(int32_t i) const {
|
||||
gameInfo * at(int32_t i) {
|
||||
return operator[](i);
|
||||
}
|
||||
gameInfo * operator[](int32_t i) const {
|
||||
gameInfo * operator[](int32_t i) {
|
||||
lock();
|
||||
gameInfo * res = NULL;
|
||||
if (i < 0 || i >= (int32_t) filteredList.size())
|
||||
return NULL;
|
||||
return filteredList[i];
|
||||
res = NULL;
|
||||
res = filteredList[i];
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
gameInfo * getGameInfo(uint64_t titleId) const;
|
||||
|
||||
@ -43,22 +55,37 @@ public:
|
||||
}
|
||||
void sortList();
|
||||
void clear();
|
||||
bool operator!() const {
|
||||
return (fullGameList.size() == 0);
|
||||
bool operator!() {
|
||||
lock();
|
||||
bool res = (fullGameList.size() == 0);
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
//! Gamelist scrolling operators
|
||||
int32_t operator+=(int32_t i) {
|
||||
return (selectedGame = (selectedGame+i) % filteredList.size());
|
||||
lock();
|
||||
int32_t res = (selectedGame = (selectedGame+i) % filteredList.size());
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
int32_t operator-=(int32_t i) {
|
||||
return (selectedGame = (selectedGame-i+filteredList.size()) % filteredList.size());
|
||||
lock();
|
||||
int32_t res = (selectedGame = (selectedGame-i+filteredList.size()) % filteredList.size());
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
int32_t operator++() {
|
||||
return (selectedGame = (selectedGame+1) % filteredList.size());
|
||||
lock();
|
||||
int32_t res = (selectedGame = (selectedGame+1) % filteredList.size());
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
int32_t operator--() {
|
||||
return (selectedGame = (selectedGame-1+filteredList.size()) % filteredList.size());
|
||||
lock();
|
||||
int32_t res = (selectedGame = (selectedGame-1+filteredList.size()) % filteredList.size());
|
||||
unlock();
|
||||
return res;
|
||||
}
|
||||
int32_t operator++(int32_t i) {
|
||||
return operator++();
|
||||
@ -66,7 +93,7 @@ public:
|
||||
int32_t operator--(int32_t i) {
|
||||
return operator--();
|
||||
}
|
||||
gameInfo * GetCurrentSelected() const {
|
||||
gameInfo * GetCurrentSelected() {
|
||||
return operator[](selectedGame);
|
||||
}
|
||||
|
||||
@ -80,6 +107,13 @@ public:
|
||||
sigslot::signal1<GameList *> titleListChanged;
|
||||
sigslot::signal1<gameInfo *> titleUpdated;
|
||||
sigslot::signal1<gameInfo *> titleAdded;
|
||||
|
||||
void lock() {
|
||||
_lock.lock();
|
||||
}
|
||||
void unlock(){
|
||||
_lock.unlock();
|
||||
}
|
||||
protected:
|
||||
|
||||
int32_t readGameList();
|
||||
@ -97,6 +131,8 @@ protected:
|
||||
int32_t selectedGame;
|
||||
std::vector<gameInfo *> filteredList;
|
||||
std::vector<gameInfo *> fullGameList;
|
||||
|
||||
CMutex _lock;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -74,6 +74,7 @@ uint64_t GuiIconGrid::getSelectedGame(void) {
|
||||
|
||||
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
||||
containerMutex.lock();
|
||||
gameList->lock();
|
||||
for(int32_t i = 0; i < gameList->size(); i++) {
|
||||
gameInfo * info = gameList->at(i);
|
||||
GameInfoContainer * container = NULL;
|
||||
@ -89,6 +90,7 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
||||
OnGameTitleAdded(info);
|
||||
}
|
||||
}
|
||||
gameList->unlock();
|
||||
containerMutex.unlock();
|
||||
bUpdatePositions = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user