Added extra checks for DataSource and DataConsumer cleanups.

git-svn-id: http://voip.null.ro/svn/yate@621 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2005-12-28 22:27:53 +00:00
parent 3f1e254612
commit 47f564a018
2 changed files with 40 additions and 6 deletions

View File

@ -157,6 +157,7 @@ const FormatInfo* FormatRepository::addFormat(const String& name, int fsize, int
return f;
}
void DataFormat::changed()
{
m_parsed = 0;
@ -170,6 +171,20 @@ const FormatInfo* DataFormat::getInfo() const
return m_parsed;
}
DataConsumer::~DataConsumer()
{
if (m_source || m_override) {
// this should not happen - but scream bloody murder if so
Debug(DebugFail,"DataConsumer destroyed with source=%p override=%p [%p]",
m_source,m_override,this);
}
if (m_source)
m_source->detach(this);
if (m_override)
m_override->detach(this);
}
void* DataConsumer::getObject(const String& name) const
{
if (name == "DataConsumer")
@ -187,6 +202,7 @@ void DataConsumer::Consume(const DataBlock& data, unsigned long tStamp, DataSour
m_timestamp = tStamp;
}
void DataSource::Forward(const DataBlock& data, unsigned long tStamp)
{
Lock lock(m_mutex);
@ -235,8 +251,17 @@ bool DataSource::detach(DataConsumer* consumer)
if (!consumer)
return false;
DDebug(DebugAll,"DataSource [%p] detaching consumer [%p]",this,consumer);
// keep the source locked to prevent races with the Forward method
Lock lock(m_mutex);
// lock the source to prevent races with the Forward method
m_mutex.lock();
bool ok = detachInternal(consumer);
m_mutex.unlock();
return ok;
}
bool DataSource::detachInternal(DataConsumer* consumer)
{
if (!consumer)
return false;
DataConsumer *temp = static_cast<DataConsumer *>(m_consumers.remove(consumer,false));
if (temp) {
if (temp->m_source == this)
@ -252,7 +277,10 @@ bool DataSource::detach(DataConsumer* consumer)
DataSource::~DataSource()
{
while (detach(static_cast<DataConsumer*>(m_consumers.get()))) ;
// keep the source locked to prevent races with the Forward method
m_mutex.lock();
while (detachInternal(static_cast<DataConsumer*>(m_consumers.get()))) ;
m_mutex.unlock();
}
void* DataSource::getObject(const String& name) const
@ -262,6 +290,7 @@ void* DataSource::getObject(const String& name) const
return DataNode::getObject(name);
}
DataEndpoint::DataEndpoint(CallEndpoint* call, const char* name)
: m_name(name), m_source(0), m_consumer(0),
m_peer(0), m_call(call),
@ -477,6 +506,7 @@ void DataEndpoint::setCallRecord(DataConsumer* consumer)
}
}
ThreadedSource::~ThreadedSource()
{
stop();
@ -508,6 +538,7 @@ Thread* ThreadedSource::thread() const
return m_thread;
}
DataTranslator::DataTranslator(const char* sFormat, const char* dFormat)
: DataConsumer(sFormat)
{

View File

@ -306,6 +306,11 @@ public:
inline DataConsumer(const char* format = "slin")
: DataNode(format), m_source(0), m_override(0), m_overrideTsDelta(0) { }
/**
* Consumer's destructor - complains loudly if still attached to a source
*/
virtual ~DataConsumer();
/**
* Get a pointer to a derived class given that class name
* @param name Name of the class we are asking for
@ -418,11 +423,9 @@ public:
{ return m_translator; }
protected:
/**
* The current position in the data - format dependent, usually samples
*/
inline void setTranslator(DataTranslator* translator)
{ m_translator = translator; }
bool detachInternal(DataConsumer* consumer);
DataTranslator* m_translator;
ObjList m_consumers;
Mutex m_mutex;