pvDatabase::removeRecord and pvRecord::remove no longer call eachother directly

This commit is contained in:
mrkraimer
2020-02-12 09:13:19 -05:00
parent 083dffac3c
commit 75c16bd423
4 changed files with 77 additions and 43 deletions
+15 -5
View File
@@ -92,18 +92,28 @@ bool PVDatabase::addRecord(PVRecordPtr const & record)
return true;
}
bool PVDatabase::removeRecord(PVRecordPtr const & record,bool callRemove)
PVRecordWPtr PVDatabase::removeFromMap(PVRecordPtr const & record)
{
if(record->getTraceLevel()>0) {
cout << "PVDatabase::removeRecord " << record->getRecordName() << endl;
}
epicsGuard<epics::pvData::Mutex> guard(mutex);
string recordName = record->getRecordName();
PVRecordMap::iterator iter = recordMap.find(recordName);
if(iter!=recordMap.end()) {
PVRecordPtr pvRecord = (*iter).second;
if(callRemove) pvRecord->remove(false);
recordMap.erase(iter);
return pvRecord->shared_from_this();
}
return PVRecordWPtr();
}
bool PVDatabase::removeRecord(PVRecordPtr const & record)
{
if(record->getTraceLevel()>0) {
cout << "PVDatabase::removeRecord " << record->getRecordName() << endl;
}
epicsGuard<epics::pvData::Mutex> guard(mutex);
PVRecordWPtr pvRecord = removeFromMap(record);
if(pvRecord.use_count()!=0) {
pvRecord.lock()->unlistenClients();
return true;
}
return false;
+15 -10
View File
@@ -65,17 +65,9 @@ PVRecord::~PVRecord()
}
}
void PVRecord::remove(bool callpvDatabaseRemoveRecord)
void PVRecord::unlistenClients()
{
if(traceLevel>0) {
cout << "PVRecord::remove() " << recordName << endl;
}
epicsGuard<epics::pvData::Mutex> guard(mutex);
if(callpvDatabaseRemoveRecord) {
PVDatabasePtr pvDatabase(PVDatabase::getMaster());
if(pvDatabase) pvDatabase->removeRecord(shared_from_this(),false);
}
pvTimeStamp.detach();
epicsGuard<epics::pvData::Mutex> guard(mutex);
for(std::list<PVListenerWPtr>::iterator iter = pvListenerList.begin();
iter!=pvListenerList.end();
iter++ )
@@ -102,6 +94,19 @@ void PVRecord::remove(bool callpvDatabaseRemoveRecord)
clientList.clear();
}
void PVRecord::remove()
{
if(traceLevel>0) {
cout << "PVRecord::remove() " << recordName << endl;
}
unlistenClients();
epicsGuard<epics::pvData::Mutex> guard(mutex);
PVDatabasePtr pvDatabase(PVDatabase::getMaster());
if(pvDatabase) pvDatabase->removeFromMap(shared_from_this());
pvTimeStamp.detach();
}
void PVRecord::initPVRecord()
{
PVRecordStructurePtr parent;
+9 -6
View File
@@ -97,10 +97,8 @@ public:
* get rid of listeners and requesters.
* If derived class overrides this then it must call PVRecord::remove()
* after it has destroyed any resorces it uses.
* @param callpvDatabaseRemoveRecord Should pvDatabase.removeRecord be called.
* Normally this is only set false by PVDatabase::removeRecord.
*/
virtual void remove(bool callpvDatabaseRemoveRecord = true);
virtual void remove();
/**
* @brief Optional method for derived class.
*
@@ -254,6 +252,9 @@ protected:
*/
void initPVRecord();
private:
friend class PVDatabase;
void unlistenClients();
PVRecordFieldPtr findPVRecordField(
PVRecordStructurePtr const & pvrs,
epics::pvData::PVFieldPtr const & pvField);
@@ -500,17 +501,19 @@ public:
/**
* @brief Remove a record.
* @param record The record to remove.
* @param callRemove Call pvRecord->remove()
* Normally this is only set false by pvRecord.remove()
*
* @return <b>true</b> if record was removed.
*/
bool removeRecord(PVRecordPtr const & record,bool callRemove = true);
bool removeRecord(PVRecordPtr const & record);
/**
* @brief Get the names of all the records in the database.
* @return The names.
*/
epics::pvData::PVStringArrayPtr getRecordNames();
private:
friend class PVRecord;
PVRecordWPtr removeFromMap(PVRecordPtr const & record);
PVDatabase();
void lock();
void unlock();