mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-27 02:10:34 +00:00
Merge pull request #12708 from unknownbrackets/i18n-lock
Core: Use a lock for i18n categories
This commit is contained in:
commit
ccd62e7612
@ -14,6 +14,7 @@ std::string I18NRepo::LanguageID() {
|
||||
}
|
||||
|
||||
void I18NRepo::Clear() {
|
||||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
for (auto iter = cats_.begin(); iter != cats_.end(); ++iter) {
|
||||
iter->second.reset();
|
||||
}
|
||||
@ -33,6 +34,7 @@ const char *I18NCategory::T(const char *key, const char *def) {
|
||||
// ILOG("translation key found in %s: %s", name_.c_str(), key);
|
||||
return iter->second.text.c_str();
|
||||
} else {
|
||||
std::lock_guard<std::mutex> guard(missedKeyLock_);
|
||||
if (def)
|
||||
missedKeyLog_[key] = def;
|
||||
else
|
||||
@ -53,6 +55,7 @@ void I18NCategory::SetMap(const std::map<std::string, std::string> &m) {
|
||||
}
|
||||
|
||||
std::shared_ptr<I18NCategory> I18NRepo::GetCategory(const char *category) {
|
||||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
auto iter = cats_.find(category);
|
||||
if (iter != cats_.end()) {
|
||||
return iter->second;
|
||||
@ -94,6 +97,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const std::string &overrid
|
||||
|
||||
const std::vector<IniFile::Section> §ions = ini.Sections();
|
||||
|
||||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
for (auto iter = sections.begin(); iter != sections.end(); ++iter) {
|
||||
if (iter->name() != "") {
|
||||
cats_[iter->name()].reset(LoadSection(&(*iter), iter->name().c_str()));
|
||||
@ -116,6 +120,7 @@ I18NCategory *I18NRepo::LoadSection(const IniFile::Section *section, const char
|
||||
void I18NRepo::SaveIni(const std::string &languageID) {
|
||||
IniFile ini;
|
||||
ini.Load(GetIniPath(languageID));
|
||||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
for (auto iter = cats_.begin(); iter != cats_.end(); ++iter) {
|
||||
std::string categoryName = iter->first;
|
||||
IniFile::Section *section = ini.GetOrCreateSection(categoryName.c_str());
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -44,20 +45,22 @@ public:
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string> &Missed() const {
|
||||
std::lock_guard<std::mutex> guard(missedKeyLock_);
|
||||
return missedKeyLog_;
|
||||
}
|
||||
|
||||
void SetMap(const std::map<std::string, std::string> &m);
|
||||
const std::map<std::string, I18NEntry> &GetMap() { return map_; }
|
||||
void ClearMissed() { missedKeyLog_.clear(); }
|
||||
const char *GetName() const { return name_.c_str(); }
|
||||
|
||||
private:
|
||||
I18NCategory(I18NRepo *repo, const char *name) : name_(name) {}
|
||||
void SetMap(const std::map<std::string, std::string> &m);
|
||||
|
||||
std::string name_;
|
||||
|
||||
std::map<std::string, I18NEntry> map_;
|
||||
mutable std::mutex missedKeyLock_;
|
||||
std::map<std::string, std::string> missedKeyLog_;
|
||||
|
||||
// Noone else can create these.
|
||||
@ -79,6 +82,7 @@ public:
|
||||
|
||||
std::shared_ptr<I18NCategory> GetCategory(const char *categoryName);
|
||||
bool HasCategory(const char *categoryName) const {
|
||||
std::lock_guard<std::mutex> guard(catsLock_);
|
||||
return cats_.find(categoryName) != cats_.end();
|
||||
}
|
||||
const char *T(const char *category, const char *key, const char *def = 0);
|
||||
@ -89,6 +93,7 @@ private:
|
||||
I18NCategory *LoadSection(const IniFile::Section *section, const char *name);
|
||||
void SaveSection(IniFile &ini, IniFile::Section *section, std::shared_ptr<I18NCategory> cat);
|
||||
|
||||
mutable std::mutex catsLock_;
|
||||
std::map<std::string, std::shared_ptr<I18NCategory>> cats_;
|
||||
std::string languageID_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user