Loads/gets the environment-information for the given top-context index, or returns zero if none exists @warning m_chainsMutex should NOT be locked when this is called, because it triggers I/O @warning no other mutexes should be locked, as that may lead to a dedalock
| 1026 | ///@warning m_chainsMutex should NOT be locked when this is called, because it triggers I/O |
| 1027 | ///@warning no other mutexes should be locked, as that may lead to a dedalock |
| 1028 | ParsingEnvironmentFile* loadInformation(uint topContextIndex) |
| 1029 | { |
| 1030 | ParsingEnvironmentFile* alreadyLoaded = findInformation(topContextIndex); |
| 1031 | if (alreadyLoaded) |
| 1032 | return alreadyLoaded; |
| 1033 | |
| 1034 | // Step two: Check if it is on disk, and if is, load it |
| 1035 | // TODO: this looks pretty dubious, shouldn't we keep the repo locked while operating on the item? |
| 1036 | const auto item = LockedItemRepository::read<EnvironmentInformation>( |
| 1037 | [req = EnvironmentInformationRequest(topContextIndex)](const EnvironmentInformationRepo& repo) { |
| 1038 | return repo.findItem(req); |
| 1039 | }); |
| 1040 | if (!item) { |
| 1041 | //No environment-information stored for this top-context |
| 1042 | return nullptr; |
| 1043 | } |
| 1044 | |
| 1045 | QMutexLocker lock(&m_chainsMutex); |
| 1046 | |
| 1047 | //Due to multi-threading, we must do this check after locking the mutex, so we can be sure we don't create the same item twice at the same time |
| 1048 | alreadyLoaded = findInformation(topContextIndex); |
| 1049 | if (alreadyLoaded) |
| 1050 | return alreadyLoaded; |
| 1051 | |
| 1052 | ///FIXME: ugly, and remove const_cast |
| 1053 | auto* ret = dynamic_cast<ParsingEnvironmentFile*>( |
| 1054 | DUChainItemSystem::self().create(const_cast<DUChainBaseData*>(reinterpret_cast<const DUChainBaseData*>( |
| 1055 | reinterpret_cast<const char*>(item) + sizeof(EnvironmentInformationItem))))); |
| 1056 | if (ret) { |
| 1057 | Q_ASSERT(ret->d_func()->classId); |
| 1058 | Q_ASSERT(ret->indexedTopContext().index() == topContextIndex); |
| 1059 | ParsingEnvironmentFilePointer retPtr(ret); |
| 1060 | |
| 1061 | m_fileEnvironmentInformations.insert(ret->url(), retPtr); |
| 1062 | |
| 1063 | Q_ASSERT(!m_indexEnvironmentInformations.contains(ret->indexedTopContext().index())); |
| 1064 | m_indexEnvironmentInformations.insert(ret->indexedTopContext().index(), retPtr); |
| 1065 | } |
| 1066 | return ret; |
| 1067 | } |
| 1068 | |
| 1069 | struct CleanupListVisitor |
| 1070 | { |
no test coverage detected