mirror of https://github.com/AxioDL/metaforce.git
SpecBase: Remove usages of const_cast
It's generally the case that mutexes are marked as mutable whenever they need to be used within a const class context, given they don't directly participate as a bitwise member of the class, but only transiently exist so that synchronization operations can occur. Given that, marking the member as mutable in this case makes sense.
This commit is contained in:
parent
b89069e1b8
commit
cf054f35a3
|
@ -746,7 +746,7 @@ void SpecBase::clearTagCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
hecl::ProjectPath SpecBase::pathFromTag(const urde::SObjectTag& tag) const {
|
hecl::ProjectPath SpecBase::pathFromTag(const urde::SObjectTag& tag) const {
|
||||||
std::unique_lock<std::mutex> lk(const_cast<SpecBase&>(*this).m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
auto search = m_tagToPath.find(tag);
|
auto search = m_tagToPath.find(tag);
|
||||||
if (search != m_tagToPath.cend())
|
if (search != m_tagToPath.cend())
|
||||||
return search->second;
|
return search->second;
|
||||||
|
@ -761,7 +761,7 @@ urde::SObjectTag SpecBase::tagFromPath(const hecl::ProjectPath& path) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpecBase::waitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut) {
|
bool SpecBase::waitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut) {
|
||||||
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
auto search = m_tagToPath.find(tag);
|
auto search = m_tagToPath.find(tag);
|
||||||
if (search == m_tagToPath.end()) {
|
if (search == m_tagToPath.end()) {
|
||||||
if (m_backgroundRunning) {
|
if (m_backgroundRunning) {
|
||||||
|
@ -787,7 +787,7 @@ const urde::SObjectTag* SpecBase::getResourceIdByName(std::string_view name) con
|
||||||
std::string lower(name);
|
std::string lower(name);
|
||||||
std::transform(lower.cbegin(), lower.cend(), lower.begin(), tolower);
|
std::transform(lower.cbegin(), lower.cend(), lower.begin(), tolower);
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lk(const_cast<SpecBase&>(*this).m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
auto search = m_catalogNameToTag.find(lower);
|
auto search = m_catalogNameToTag.find(lower);
|
||||||
if (search == m_catalogNameToTag.end()) {
|
if (search == m_catalogNameToTag.end()) {
|
||||||
if (m_backgroundRunning) {
|
if (m_backgroundRunning) {
|
||||||
|
@ -811,7 +811,7 @@ FourCC SpecBase::getResourceTypeById(urde::CAssetId id) const {
|
||||||
if (!id.IsValid())
|
if (!id.IsValid())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lk(const_cast<SpecBase&>(*this).m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
urde::SObjectTag searchTag = {FourCC(), id};
|
urde::SObjectTag searchTag = {FourCC(), id};
|
||||||
auto search = m_tagToPath.find(searchTag);
|
auto search = m_tagToPath.find(searchTag);
|
||||||
if (search == m_tagToPath.end()) {
|
if (search == m_tagToPath.end()) {
|
||||||
|
@ -901,7 +901,7 @@ void SpecBase::readCatalog(const hecl::ProjectPath& catalogPath, athena::io::YAM
|
||||||
continue;
|
continue;
|
||||||
urde::SObjectTag pathTag = tagFromPath(path);
|
urde::SObjectTag pathTag = tagFromPath(path);
|
||||||
if (pathTag) {
|
if (pathTag) {
|
||||||
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
m_catalogNameToTag[pLower] = pathTag;
|
m_catalogNameToTag[pLower] = pathTag;
|
||||||
m_catalogTagToNames[pathTag].insert(p.first);
|
m_catalogTagToNames[pathTag].insert(p.first);
|
||||||
|
|
||||||
|
@ -1111,7 +1111,7 @@ void SpecBase::backgroundIndexProc() {
|
||||||
Log.report(logvisor::Info, fmt(_SYS_STR("Cache index of '{}' loading")), getOriginalSpec().m_name);
|
Log.report(logvisor::Info, fmt(_SYS_STR("Cache index of '{}' loading")), getOriginalSpec().m_name);
|
||||||
athena::io::YAMLDocReader cacheReader;
|
athena::io::YAMLDocReader cacheReader;
|
||||||
if (cacheReader.parse(&reader)) {
|
if (cacheReader.parse(&reader)) {
|
||||||
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
size_t tagCount = cacheReader.getRootNode()->m_mapChildren.size();
|
size_t tagCount = cacheReader.getRootNode()->m_mapChildren.size();
|
||||||
m_tagToPath.reserve(tagCount);
|
m_tagToPath.reserve(tagCount);
|
||||||
m_pathToTag.reserve(tagCount);
|
m_pathToTag.reserve(tagCount);
|
||||||
|
@ -1147,7 +1147,7 @@ void SpecBase::backgroundIndexProc() {
|
||||||
athena::io::FileReader nreader(nameCachePath.getAbsolutePath());
|
athena::io::FileReader nreader(nameCachePath.getAbsolutePath());
|
||||||
athena::io::YAMLDocReader nameReader;
|
athena::io::YAMLDocReader nameReader;
|
||||||
if (nameReader.parse(&nreader)) {
|
if (nameReader.parse(&nreader)) {
|
||||||
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
m_catalogNameToTag.reserve(nameReader.getRootNode()->m_mapChildren.size());
|
m_catalogNameToTag.reserve(nameReader.getRootNode()->m_mapChildren.size());
|
||||||
m_catalogTagToNames.reserve(nameReader.getRootNode()->m_mapChildren.size());
|
m_catalogTagToNames.reserve(nameReader.getRootNode()->m_mapChildren.size());
|
||||||
for (const auto& child : nameReader.getRootNode()->m_mapChildren) {
|
for (const auto& child : nameReader.getRootNode()->m_mapChildren) {
|
||||||
|
@ -1198,7 +1198,7 @@ void SpecBase::beginBackgroundIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpecBase::waitForIndexComplete() const {
|
void SpecBase::waitForIndexComplete() const {
|
||||||
std::unique_lock<std::mutex> lk(const_cast<SpecBase&>(*this).m_backgroundIndexMutex);
|
std::unique_lock lk(m_backgroundIndexMutex);
|
||||||
while (m_backgroundRunning) {
|
while (m_backgroundRunning) {
|
||||||
lk.unlock();
|
lk.unlock();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(2));
|
std::this_thread::sleep_for(std::chrono::milliseconds(2));
|
||||||
|
|
|
@ -175,7 +175,7 @@ protected:
|
||||||
|
|
||||||
hecl::blender::Token m_backgroundBlender;
|
hecl::blender::Token m_backgroundBlender;
|
||||||
std::thread m_backgroundIndexTh;
|
std::thread m_backgroundIndexTh;
|
||||||
std::mutex m_backgroundIndexMutex;
|
mutable std::mutex m_backgroundIndexMutex;
|
||||||
bool m_backgroundRunning = false;
|
bool m_backgroundRunning = false;
|
||||||
|
|
||||||
void readCatalog(const hecl::ProjectPath& catalogPath, athena::io::YAMLDocWriter& nameWriter);
|
void readCatalog(const hecl::ProjectPath& catalogPath, athena::io::YAMLDocWriter& nameWriter);
|
||||||
|
|
Loading…
Reference in New Issue