1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Performance++, Memory--

This commit is contained in:
Uwe L. Korn
2013-06-26 12:03:11 +02:00
committed by Michael Zanetti
parent 546f54f196
commit 7daebc655a
3 changed files with 10 additions and 8 deletions

View File

@@ -28,6 +28,7 @@
#include "sip/SipInfo.h" #include "sip/SipInfo.h"
#include "sip/SipPlugin.h" #include "sip/SipPlugin.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/WeakObjectHash.h"
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <qtconcurrentrun.h> #include <qtconcurrentrun.h>
@@ -35,21 +36,21 @@
/* Management of ConnectionManagers */ /* Management of ConnectionManagers */
static QMutex nodeMapMutex; static QMutex nodeMapMutex;
static QMap< QString, QWeakPointer< ConnectionManager > > connectionManagers; static Tomahawk::Utils::WeakObjectHash< ConnectionManager > connectionManagers;
static QMap< QString, QSharedPointer< ConnectionManager > > activeConnectionManagers; static QHash< QString, QSharedPointer< ConnectionManager > > activeConnectionManagers;
QSharedPointer<ConnectionManager> QSharedPointer<ConnectionManager>
ConnectionManager::getManagerForNodeId( const QString &nodeid ) ConnectionManager::getManagerForNodeId( const QString &nodeid )
{ {
QMutexLocker locker( &nodeMapMutex ); QMutexLocker locker( &nodeMapMutex );
if ( connectionManagers.contains( nodeid ) && !connectionManagers.value( nodeid ).isNull() ) { if ( connectionManagers.hash().contains( nodeid ) && !connectionManagers.hash().value( nodeid ).isNull() ) {
return connectionManagers.value( nodeid ).toStrongRef(); return connectionManagers.hash().value( nodeid ).toStrongRef();
} }
// There exists no connection for this nodeid // There exists no connection for this nodeid
QSharedPointer< ConnectionManager > manager( new ConnectionManager( nodeid ) ); QSharedPointer< ConnectionManager > manager( new ConnectionManager( nodeid ) );
manager->setWeakRef( manager.toWeakRef() ); manager->setWeakRef( manager.toWeakRef() );
connectionManagers[nodeid] = manager->weakRef(); connectionManagers.insert( nodeid, manager.toWeakRef() );
return manager; return manager;
} }

View File

@@ -49,7 +49,7 @@ public:
*/ */
static void setActive( bool active, const QString& nodeid, const QSharedPointer<ConnectionManager>& manager ); static void setActive( bool active, const QString& nodeid, const QSharedPointer<ConnectionManager>& manager );
~ConnectionManager(); virtual ~ConnectionManager();
/** /**
* Receive incoming SipInfos and start a new thread to connect to this peer. * Receive incoming SipInfos and start a new thread to connect to this peer.

View File

@@ -492,7 +492,7 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
peerInfoDebug(peerInfo) << "we need to establish the connection now... thinking"; peerInfoDebug(peerInfo) << "we need to establish the connection now... thinking";
if ( !connectedToSession( peerInfo->nodeId() ) ) if ( !connectedToSession( peerInfo->nodeId() ) )
{ {
ConnectionManager::getManagerForNodeId( peerInfo->nodeId() )->handleSipInfo( peerInfo ); handleSipInfo( peerInfo );
} }
else else
{ {
@@ -556,7 +556,8 @@ Servent::handleSipInfo( const Tomahawk::peerinfo_ptr& peerInfo )
if ( peerInfo->sipInfos().isEmpty() ) if ( peerInfo->sipInfos().isEmpty() )
return; return;
ConnectionManager::getManagerForNodeId( peerInfo->nodeId() )->handleSipInfo( peerInfo ); QSharedPointer<ConnectionManager> manager = ConnectionManager::getManagerForNodeId( peerInfo->nodeId() );
manager->handleSipInfo( peerInfo );
} }