*
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "ResourceCache.hpp"
|
||||
#include "AssetsManager.hpp"
|
||||
#include "sqlite3.h"
|
||||
#include <fstream>
|
||||
|
||||
@@ -285,12 +285,12 @@ std::string CacheDatabase::hashToString(Hash_t hash) {
|
||||
// return hash;
|
||||
// }
|
||||
|
||||
coro<> ResourceHandler::asyncDestructor() {
|
||||
coro<> AssetsManager::asyncDestructor() {
|
||||
assert(NeedShutdown); // Нормальный shutdown должен быть вызван
|
||||
co_await IAsyncDestructible::asyncDestructor();
|
||||
}
|
||||
|
||||
void ResourceHandler::readWriteThread(AsyncUseControl::Lock lock) {
|
||||
void AssetsManager::readWriteThread(AsyncUseControl::Lock lock) {
|
||||
LOG.info() << "Поток чтения/записи запущен";
|
||||
|
||||
while(!NeedShutdown || !WriteQueue.get_read().empty()) {
|
||||
@@ -412,10 +412,10 @@ void ResourceHandler::readWriteThread(AsyncUseControl::Lock lock) {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
ResourceHandler::ResourceHandler(boost::asio::io_context &ioc, const fs::path &cachePath,
|
||||
AssetsManager::AssetsManager(boost::asio::io_context &ioc, const fs::path &cachePath,
|
||||
size_t maxCacheDirectorySize, size_t maxLifeTime)
|
||||
: IAsyncDestructible(ioc),
|
||||
OffThread(&ResourceHandler::readWriteThread, this, AUC.use())
|
||||
OffThread(&AssetsManager::readWriteThread, this, AUC.use())
|
||||
{
|
||||
LOG.info() << "Инициализировано хранилище кеша: " << cachePath.c_str();
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common/Abstract.hpp"
|
||||
#include <array>
|
||||
#include <boost/lockfree/spsc_queue.hpp>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
@@ -15,7 +12,6 @@
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
namespace LV::Client {
|
||||
@@ -91,9 +87,9 @@ public:
|
||||
|
||||
Обработка файлов в отдельном потоке
|
||||
*/
|
||||
class ResourceHandler : public IAsyncDestructible {
|
||||
class AssetsManager : public IAsyncDestructible {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<ResourceHandler>;
|
||||
using Ptr = std::shared_ptr<AssetsManager>;
|
||||
|
||||
struct ResourceKey {
|
||||
Hash_t Hash;
|
||||
@@ -101,15 +97,11 @@ public:
|
||||
std::string Domain, Key;
|
||||
};
|
||||
|
||||
protected:
|
||||
ResourceHandler(boost::asio::io_context &ioc, const fs::path &cachePath,
|
||||
size_t maxCacheDatabaseSize, size_t maxLifeTime);
|
||||
|
||||
public:
|
||||
virtual ~ResourceHandler();
|
||||
static std::shared_ptr<ResourceHandler> Create(asio::io_context &ioc, const fs::path& cachePath,
|
||||
virtual ~AssetsManager();
|
||||
static std::shared_ptr<AssetsManager> Create(asio::io_context &ioc, const fs::path& cachePath,
|
||||
size_t maxCacheDirectorySize = 8*1024*1024*1024ULL, size_t maxLifeTime = 7*24*60*60) {
|
||||
return createShared(ioc, new ResourceHandler(ioc, cachePath, maxCacheDirectorySize, maxLifeTime));
|
||||
return createShared(ioc, new AssetsManager(ioc, cachePath, maxCacheDirectorySize, maxLifeTime));
|
||||
}
|
||||
|
||||
// Добавить новый полученный с сервера ресурс
|
||||
@@ -190,6 +182,11 @@ private:
|
||||
bool NeedShutdown = false;
|
||||
std::thread OffThread;
|
||||
|
||||
|
||||
virtual coro<> asyncDestructor();
|
||||
AssetsManager(boost::asio::io_context &ioc, const fs::path &cachePath,
|
||||
size_t maxCacheDatabaseSize, size_t maxLifeTime);
|
||||
|
||||
void readWriteThread(AsyncUseControl::Lock lock);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user