| 372 | } |
| 373 | |
| 374 | void hcf_cache::unregister_hcf_object(hcf_object_id id) { |
| 375 | std::lock_guard<std::mutex> lock{_mutex}; |
| 376 | |
| 377 | auto it = _hcf_objects.find(id); |
| 378 | if(it != _hcf_objects.end()) { |
| 379 | // First remove the HCF object as a symbol provider for runtime linking and |
| 380 | // symbol resolution. This ensures that it gets no longer selected |
| 381 | // for symbol resolution. |
| 382 | |
| 383 | // 1. Go through each symbol list (all device images) exported by this |
| 384 | // HCF file |
| 385 | for_each_exported_symbol_list( |
| 386 | *(it->second), [&](const common::hcf_container::node* image_node, |
| 387 | const std::vector<std::string> &exported_symbols) { |
| 388 | // 2. Iterate over all symbols exported in this HCF |
| 389 | for (const auto &symbol : exported_symbols) { |
| 390 | // 3. Remove all references to this HCF in the symbol providers map |
| 391 | auto& symbol_providers = _exported_symbol_providers[symbol]; |
| 392 | symbol_providers.erase( |
| 393 | std::remove_if(symbol_providers.begin(), symbol_providers.end(), |
| 394 | [&](const device_image_id &img) { |
| 395 | return img.hcf_id == id; |
| 396 | }), |
| 397 | symbol_providers.end()); |
| 398 | } |
| 399 | }); |
| 400 | // Then we can remove the HCF itself. |
| 401 | // Note: We don't necessarily need to remove the HCF kernel info, since |
| 402 | // just maintaining this data won't have any side effects as long as |
| 403 | // the HCF object is no longer selected for execution. |
| 404 | _hcf_objects.erase(id); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | const common::hcf_container* hcf_cache::get_hcf(hcf_object_id obj) const { |
| 409 | std::lock_guard<std::mutex> lock{_mutex}; |
no test coverage detected