1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

Loosen destructor calls and empty source_ptr instead of deleting it.

This commit is contained in:
Uwe L. Korn
2013-06-17 07:58:56 +02:00
parent e7c1dafcda
commit 01a5f20c9a
2 changed files with 14 additions and 6 deletions

View File

@@ -111,7 +111,8 @@ Source::setControlConnection( ControlConnection* cc )
// Tell the ControlConnection it is not anymore responsible for us.
d->cc->unbindFromSource();
// This ControlConnection is not needed anymore, get rid of it!
d->cc->deleteLater();
// (But decouple the deletion it from the current activity)
QMetaObject::invokeMethod( d->cc.data(), "deleteLater", Qt::QueuedConnection);
// Use new ControlConnection
d->cc = cc;
return true;

View File

@@ -55,12 +55,14 @@ ControlConnection::ControlConnection( Servent* parent )
ControlConnection::~ControlConnection()
{
Q_D( ControlConnection );
QReadLocker locker( &d->sourceLock );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << id() << name();
if ( !d->source.isNull() )
{
d->source->setOffline();
QReadLocker locker( &d->sourceLock );
if ( !d->source.isNull() )
{
d->source->setOffline();
}
}
delete d->pingtimer;
@@ -86,7 +88,7 @@ ControlConnection::unbindFromSource()
{
Q_D( ControlConnection );
QWriteLocker locker( &d->sourceLock );
d->source.clear();
d->source = Tomahawk::source_ptr();
}
@@ -105,12 +107,14 @@ ControlConnection::setup()
{
Q_D( ControlConnection );
qDebug() << Q_FUNC_INFO << id() << name();
QWriteLocker sourceLocker( &d->sourceLock );
// We need to manually lock, so that we can release before the end of the function
d->sourceLock.lockForWrite();
if ( !d->source.isNull() )
{
qDebug() << "This source seems to be online already.";
Q_ASSERT( false );
d->sourceLock.unlock();
return;
}
@@ -137,9 +141,12 @@ ControlConnection::setup()
connect( d->pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
d->pingtimer->start();
d->pingtimer_mark.start();
d->sourceLock.unlock();
}
else
{
// Unlock before we delete ourselves
d->sourceLock.unlock();
// There is already another ControlConnection in use, we are useless.
deleteLater();
}