perf: 修改异步加载资源的方式

This commit is contained in:
MistEO
2023-05-02 15:16:07 +08:00
parent 8bd75c87a0
commit 3d7172a3d2
5 changed files with 73 additions and 44 deletions

View File

@@ -7,27 +7,15 @@
bool asst::AbstractConfig::load(const std::filesystem::path& path)
{
return _load(path);
}
std::string class_name = utils::demangle(typeid(*this).name());
void asst::AbstractConfig::async_load(const std::filesystem::path& path)
{
m_load_future = std::async(std::launch::async, &AbstractConfig::_load, this, path);
}
bool asst::AbstractConfig::_load(std::filesystem::path path)
{
if (!std::filesystem::exists(path) || !std::filesystem::is_regular_file(path)) {
std::string class_name = utils::demangle(typeid(*this).name());
Log.error(class_name, "file does not exist", path);
Log.error(class_name, __FUNCTION__, "file does not exist", path);
return false;
}
m_path = path;
std::unique_lock lock(m_load_mutex);
std::string class_name = utils::demangle(typeid(*this).name());
LogTraceScope(class_name);
LogTraceScope(class_name + " :: " + __FUNCTION__);
Log.info(path);
auto ret = json::open(path, true);