diff --git a/src/Variable/VariableController2.cpp b/src/Variable/VariableController2.cpp index c9fb7e5..19d918c 100644 --- a/src/Variable/VariableController2.cpp +++ b/src/Variable/VariableController2.cpp @@ -116,6 +116,7 @@ class VariableController2::VariableController2Private QMap> _synchronizationGroups; QReadWriteLock _lock{QReadWriteLock::Recursive}; }_maps; + std::vector _variablesToRemove; QThreadPool* _ThreadPool; VCTransactionsQueues _transactions; std::unique_ptr _cacheStrategy; @@ -129,6 +130,19 @@ class VariableController2::VariableController2Private this->_processTransactions(); } + void _cleanupVariables() + { + for(auto id:_variablesToRemove) + { + auto v = this->variable(id); + if(!hasPendingTransactions(v)) + { + _variablesToRemove.erase(std::remove(_variablesToRemove.begin(), _variablesToRemove.end(), id), _variablesToRemove.end()); + this->deleteVariable(v); + } + } + } + void _processTransactions(bool fragmented=false) { auto nextTransactions = _transactions.nextTransactions(); @@ -173,6 +187,9 @@ class VariableController2::VariableController2Private } } } + //after each transaction update we get a new distribution of idle and working variables + //so we can delete variables which are waiting to be deleted if they are now idle + _cleanupVariables(); } std::map _computeAllRangesInGroup(const std::shared_ptr& refVar, DateTimeRange r) @@ -304,7 +321,10 @@ public: void deleteVariable(const std::shared_ptr& variable) { - _maps.removeVariable(variable); + if(!hasPendingTransactions(variable)) + _maps.removeVariable(variable); + else + _variablesToRemove.push_back(variable->ID()); } void asyncChangeRange(const std::shared_ptr& variable, const DateTimeRange& r) diff --git a/tests/Variable/TestVariableController2.cpp b/tests/Variable/TestVariableController2.cpp index a10a2d8..2a85957 100644 --- a/tests/Variable/TestVariableController2.cpp +++ b/tests/Variable/TestVariableController2.cpp @@ -125,6 +125,7 @@ private slots: } void testCache() { + QSKIP("The cache is disabled for now"); TEST_VC2_FIXTURE(10); TEST_VC2_CREATE_DEFAULT_VAR(var1); check_variable_state>(var1, range); diff --git a/tests/Variable/TestVariableController2WithSync.cpp b/tests/Variable/TestVariableController2WithSync.cpp index 0c84707..046f197 100644 --- a/tests/Variable/TestVariableController2WithSync.cpp +++ b/tests/Variable/TestVariableController2WithSync.cpp @@ -61,6 +61,7 @@ private slots: auto var1 = vc.createVariable("var1", {}, provider, range); QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); QVERIFY(!callbackCalled); + while (!vc.isReady(var1)) {qApp->processEvents();} vc.deleteVariable(var1); QVERIFY(!SciQLop::containers::contains(vc.variables(), var1)); QVERIFY(callbackCalled);