#include #include #include #include #include namespace mbgl { std::shared_ptr FileSource::getSharedFileSource(const ResourceOptions& options) { static std::mutex mutex; static std::map> fileSources; std::lock_guard lock(mutex); // Purge entries no longer in use. for (auto it = fileSources.begin(); it != fileSources.end();) { it = it->second.expired() ? fileSources.erase(it) : ++it; } const uint64_t context = reinterpret_cast(options.platformContext()); const std::string key = options.baseURL() + '|' + options.accessToken() + '|' + options.cachePath() + '|' + util::toString(context); std::shared_ptr fileSource; auto tuple = fileSources.find(key); if (tuple != fileSources.end()) { fileSource = tuple->second.lock(); } if (!fileSource) { fileSources[key] = fileSource = createPlatformFileSource(options); } return fileSource; } } // namespace mbgl