本文整理汇总了C++中std::unique_ptr::Async方法的典型用法代码示例。如果您正苦于以下问题:C++ unique_ptr::Async方法的具体用法?C++ unique_ptr::Async怎么用?C++ unique_ptr::Async使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::unique_ptr
的用法示例。
在下文中一共展示了unique_ptr::Async方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CleanCache
void CleanCache(agi::fs::path const& directory, std::string const& file_type, uint64_t max_size, uint64_t max_files) {
static std::unique_ptr<agi::dispatch::Queue> queue;
if (!queue)
queue = agi::dispatch::Create();
max_size <<= 20;
if (max_files == 0)
max_files = std::numeric_limits<uint64_t>::max();
queue->Async([=]{
LOG_D("utils/clean_cache") << "cleaning " << directory/file_type;
uint64_t total_size = 0;
std::multimap<int64_t, agi::fs::path> cachefiles;
for (auto const& file : agi::fs::DirectoryIterator(directory, file_type)) {
agi::fs::path path = directory/file;
cachefiles.insert(std::make_pair(agi::fs::ModifiedTime(path), path));
total_size += agi::fs::Size(path);
}
if (cachefiles.size() <= max_files && total_size <= max_size) {
LOG_D("utils/clean_cache") << boost::format("cache does not need cleaning (maxsize=%d, cursize=%d, maxfiles=%d, numfiles=%d), exiting")
% max_size % total_size % max_files % cachefiles.size();
return;
}
int deleted = 0;
for (auto const& i : cachefiles) {
// stop cleaning?
if ((total_size <= max_size && cachefiles.size() - deleted <= max_files) || cachefiles.size() - deleted < 2)
break;
uint64_t size = agi::fs::Size(i.second);
try {
agi::fs::Remove(i.second);
LOG_D("utils/clean_cache") << "deleted " << i.second;
}
catch (agi::Exception const& e) {
LOG_D("utils/clean_cache") << "failed to delete file " << i.second << ": " << e.GetChainedMessage();
continue;
}
total_size -= size;
++deleted;
}
LOG_D("utils/clean_cache") << "deleted " << deleted << " files, exiting";
});
}