@param retries When this is nonzero, then doMoreCleanup will do the specified amount of cycles doing the cleanup without permanently locking the du-chain. During these steps the consistency of the disk-storage is not guaranteed, but only few changes will be done during these steps, so the final step where the duchain is permanently locked is much faster.
| 787 | ///of the disk-storage is not guaranteed, but only few changes will be done during these steps, |
| 788 | ///so the final step where the duchain is permanently locked is much faster. |
| 789 | void doMoreCleanup(int retries = 0, LockFlag lockFlag = BlockingLock) |
| 790 | { |
| 791 | if (m_cleanupDisabled) |
| 792 | return; |
| 793 | |
| 794 | //This mutex makes sure that there's never 2 threads at he same time trying to clean up |
| 795 | QMutexLocker lockCleanupMutex(&cleanupMutex()); |
| 796 | |
| 797 | if (m_destroyed || m_cleanupDisabled) |
| 798 | return; |
| 799 | |
| 800 | Q_ASSERT(!instance->lock()->currentThreadHasReadLock() && !instance->lock()->currentThreadHasWriteLock()); |
| 801 | DUChainWriteLocker writeLock(instance->lock()); |
| 802 | |
| 803 | //This is used to stop all parsing before starting to do the cleanup. This way less happens during the |
| 804 | //soft cleanups, and we have a good chance that during the "hard" cleanup only few data has to be written. |
| 805 | QList<QReadWriteLock*> locked; |
| 806 | |
| 807 | if (lockFlag != NoLock) { |
| 808 | QList<ILanguageSupport*> languages; |
| 809 | if (ICore* core = ICore::self()) |
| 810 | if (ILanguageController* lc = core->languageController()) |
| 811 | languages = lc->loadedLanguages(); |
| 812 | |
| 813 | writeLock.unlock(); |
| 814 | |
| 815 | //Here we wait for all parsing-threads to stop their processing |
| 816 | for (const auto language : std::as_const(languages)) { |
| 817 | if (lockFlag == TryLock) { |
| 818 | if (!language->parseLock()->tryLockForWrite()) { |
| 819 | qCDebug(LANGUAGE) << "Aborting cleanup because language plugin is still parsing:" << |
| 820 | language->name(); |
| 821 | // some language is still parsing, don't interfere with the cleanup |
| 822 | for (auto* lock : std::as_const(locked)) { |
| 823 | lock->unlock(); |
| 824 | } |
| 825 | |
| 826 | return; |
| 827 | } |
| 828 | } else { |
| 829 | language->parseLock()->lockForWrite(); |
| 830 | } |
| 831 | locked << language->parseLock(); |
| 832 | } |
| 833 | |
| 834 | writeLock.lock(); |
| 835 | |
| 836 | globalItemRepositoryRegistry().lockForWriting(); |
| 837 | qCDebug(LANGUAGE) << "starting cleanup"; |
| 838 | } |
| 839 | |
| 840 | QTime startTime = QTime::currentTime(); |
| 841 | |
| 842 | storeAllInformation(!retries, writeLock); //Puts environment-information into a repository |
| 843 | |
| 844 | //We don't need to increase the reference-count, since the cleanup-mutex is locked |
| 845 | QSet<TopDUContext*> workOnContexts; |
| 846 |
no test coverage detected