MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getBundle

Method getBundle

valdi/src/valdi/runtime/Resources/ResourceManager.cpp:307–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307Ref<Bundle> ResourceManager::getBundle(const StringBox& bundleName) {
308 std::unique_lock<Mutex> lock(_mutex);
309 const auto& it = _bundleByName.find(bundleName);
310 if (it != _bundleByName.end()) {
311 return it->second;
312 }
313
314 VALDI_TRACE_META("Valdi.loadBundle", bundleName);
315 snap::utils::time::StopWatch sw;
316 sw.start();
317
318 auto bundleInitializer = registerBundle(bundleName);
319 auto inlineAssetsEnabled = _inlineAssetsEnabled;
320
321 // Snapshot the mmap/metrics settings while we still hold _mutex. getArchiveForModule runs below
322 // while the BundleInitializer holds the Bundle's mutex; it must not take _mutex itself, or it
323 // would invert the cleanup path's (_mutex -> Bundle mutex) order and can deadlock.
324 bool useMmap = false;
325 if (_runtimeTweaks != nullptr) {
326 useMmap = _runtimeTweaks->enableMmapModuleArchives() && !_mmapCacheDirectory.empty();
327 }
328 auto mmapCacheDir = _mmapCacheDirectory;
329 auto metrics = _metrics;
330
331 // We now have a lock on the Bundle itself. Release our lock so that
332 // other threads can query the ResourceManager on other bundles.
333 lock.unlock();
334
335 auto assetPackageKey = STRING_LITERAL("res.assetpackage");
336 auto hasAssetPackage = false;
337
338 auto archiveResult = getArchiveForModule(bundleName, useMmap, mmapCacheDir, metrics);
339 if (!archiveResult) {
340 if (!_hotReloaderEnabled) {
341 VALDI_ERROR(_logger, "Failed to load archive of Module '{}': {}", bundleName, archiveResult.error());
342 }
343 initializeBundle(bundleInitializer, makeShared<ValdiModuleArchive>());
344 } else {
345 hasAssetPackage = inlineAssetsEnabled && archiveResult.value()->containsEntry(assetPackageKey);
346 initializeBundle(bundleInitializer, archiveResult.value());
347 }
348
349 populateSourceMap(bundleName, *bundleInitializer.getBundle());
350
351 if (hasAssetPackage) {
352 insertAssetPackageInBundle(bundleInitializer.getBundle(),
353 bundleInitializer.getBundle()->getEntry(assetPackageKey).value());
354 }
355
356 if (Valdi::traceLoadModules) {
357 VALDI_INFO(_logger, "Loaded bundle '{}' in {}", bundleName, sw.elapsed());
358 }
359
360 return bundleInitializer.getBundle();
361}
362
363/**
364 * Returns the list of all loaded bundle names.

Callers 15

warmUpBundlesMethod · 0.95
hotReloadMethod · 0.80
TEST_PFunction · 0.80
TESTFunction · 0.80
getAssetMethod · 0.80
getModuleEntryMethod · 0.80
updateResourcesMethod · 0.80
operator()Method · 0.80
initializeBundleMethod · 0.80
onAssetCatalogChangedMethod · 0.80

Calls 11

containsEntryMethod · 0.80
endMethod · 0.65
startMethod · 0.65
errorMethod · 0.65
valueMethod · 0.65
findMethod · 0.45
emptyMethod · 0.45
unlockMethod · 0.45
getEntryMethod · 0.45
elapsedMethod · 0.45

Tested by 3

hotReloadMethod · 0.64
TEST_PFunction · 0.64
TESTFunction · 0.64