mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-15 15:30:29 +02:00
Config: Cleanup recent on a thread.
This commit is contained in:
1 parent
aad5082d55
commit
c04de9dd79
2 files changed
+71
-33
No files matched your search
+68
-24
@@ -19,8 +19,10 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
@@ -56,6 +58,9 @@ http::Downloader g_DownloadManager;
|
||||
Config g_Config;
|
||||
|
||||
bool jitForcedOff;
|
||||
static std::mutex recentIsosLock;
|
||||
static std::mutex recentIsosThreadLock;
|
||||
static std::thread recentIsosThread;
|
||||
|
||||
#ifdef _DEBUG
|
||||
static const char *logSectionName = "LogDebug";
|
||||
@@ -1206,6 +1211,19 @@ static void IterateSettings(IniFile &iniFile, std::function<void(Section *sectio
|
||||
}
|
||||
}
|
||||
|
||||
static void ResetRecentIsosThread() {
|
||||
std::lock_guard<std::mutex> guard(recentIsosThreadLock);
|
||||
if (recentIsosThread.joinable())
|
||||
recentIsosThread.join();
|
||||
}
|
||||
|
||||
static void SetRecentIsosThread(std::function<void()> f) {
|
||||
std::lock_guard<std::mutex> guard(recentIsosThreadLock);
|
||||
if (recentIsosThread.joinable())
|
||||
recentIsosThread.join();
|
||||
recentIsosThread = std::thread(f);
|
||||
}
|
||||
|
||||
Config::Config() {
|
||||
}
|
||||
|
||||
@@ -1213,6 +1231,7 @@ Config::~Config() {
|
||||
if (bUpdatedInstanceCounter) {
|
||||
ShutdownInstanceCounter();
|
||||
}
|
||||
ResetRecentIsosThread();
|
||||
}
|
||||
|
||||
std::map<std::string, std::pair<std::string, int>> GetLangValuesMapping() {
|
||||
@@ -1315,6 +1334,8 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
|
||||
iMaxRecent = 60;
|
||||
|
||||
if (iMaxRecent > 0) {
|
||||
ResetRecentIsosThread();
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
recentIsos.clear();
|
||||
for (int i = 0; i < iMaxRecent; i++) {
|
||||
char keyName[64];
|
||||
@@ -1470,9 +1491,11 @@ bool Config::Save(const char *saveReason) {
|
||||
Section *recent = iniFile.GetOrCreateSection("Recent");
|
||||
recent->Set("MaxRecent", iMaxRecent);
|
||||
|
||||
ResetRecentIsosThread();
|
||||
for (int i = 0; i < iMaxRecent; i++) {
|
||||
char keyName[64];
|
||||
snprintf(keyName, sizeof(keyName), "FileName%d", i);
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
if (i < (int)recentIsos.size()) {
|
||||
recent->Set(keyName, recentIsos[i]);
|
||||
} else {
|
||||
@@ -1610,6 +1633,8 @@ void Config::AddRecent(const std::string &file) {
|
||||
// We'll add it back below. This makes sure it's at the front, and only once.
|
||||
RemoveRecent(file);
|
||||
|
||||
ResetRecentIsosThread();
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
const std::string filename = File::ResolvePath(file);
|
||||
recentIsos.insert(recentIsos.begin(), filename);
|
||||
if ((int)recentIsos.size() > iMaxRecent)
|
||||
@@ -1621,6 +1646,8 @@ void Config::RemoveRecent(const std::string &file) {
|
||||
if (iMaxRecent <= 0)
|
||||
return;
|
||||
|
||||
ResetRecentIsosThread();
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
const std::string filename = File::ResolvePath(file);
|
||||
for (auto iter = recentIsos.begin(); iter != recentIsos.end();) {
|
||||
const std::string recent = File::ResolvePath(*iter);
|
||||
@@ -1634,35 +1661,52 @@ void Config::RemoveRecent(const std::string &file) {
|
||||
}
|
||||
|
||||
void Config::CleanRecent() {
|
||||
double startTime = time_now_d();
|
||||
SetRecentIsosThread([this] {
|
||||
double startTime = time_now_d();
|
||||
|
||||
std::vector<std::string> cleanedRecent;
|
||||
for (size_t i = 0; i < recentIsos.size(); i++) {
|
||||
bool exists = false;
|
||||
Path path = Path(recentIsos[i]);
|
||||
switch (path.Type()) {
|
||||
case PathType::CONTENT_URI:
|
||||
case PathType::NATIVE:
|
||||
exists = File::Exists(path);
|
||||
break;
|
||||
default:
|
||||
FileLoader *loader = ConstructFileLoader(path);
|
||||
exists = loader->ExistsFast();
|
||||
delete loader;
|
||||
break;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
std::vector<std::string> cleanedRecent;
|
||||
for (size_t i = 0; i < recentIsos.size(); i++) {
|
||||
bool exists = false;
|
||||
Path path = Path(recentIsos[i]);
|
||||
switch (path.Type()) {
|
||||
case PathType::CONTENT_URI:
|
||||
case PathType::NATIVE:
|
||||
exists = File::Exists(path);
|
||||
break;
|
||||
default:
|
||||
FileLoader *loader = ConstructFileLoader(path);
|
||||
exists = loader->ExistsFast();
|
||||
delete loader;
|
||||
break;
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
// Make sure we don't have any redundant items.
|
||||
auto duplicate = std::find(cleanedRecent.begin(), cleanedRecent.end(), recentIsos[i]);
|
||||
if (duplicate == cleanedRecent.end()) {
|
||||
cleanedRecent.push_back(recentIsos[i]);
|
||||
if (exists) {
|
||||
// Make sure we don't have any redundant items.
|
||||
auto duplicate = std::find(cleanedRecent.begin(), cleanedRecent.end(), recentIsos[i]);
|
||||
if (duplicate == cleanedRecent.end()) {
|
||||
cleanedRecent.push_back(recentIsos[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INFO_LOG(SYSTEM, "CleanRecent took %0.2f", time_now_d() - startTime);
|
||||
recentIsos = cleanedRecent;
|
||||
INFO_LOG(SYSTEM, "CleanRecent took %0.2f", time_now_d() - startTime);
|
||||
recentIsos = cleanedRecent;
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::string> Config::RecentIsos() const {
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
return recentIsos;
|
||||
}
|
||||
bool Config::HasRecentIsos() const {
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
return !recentIsos.empty();
|
||||
}
|
||||
void Config::ClearRecentIsos() {
|
||||
ResetRecentIsosThread();
|
||||
std::lock_guard<std::mutex> guard(recentIsosLock);
|
||||
recentIsos.clear();
|
||||
}
|
||||
|
||||
void Config::SetSearchPath(const Path &searchPath) {
|
||||
|
||||
Reference in new issue
Block a user