1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 20:00:13 +02:00

Only delete qnam objects in liblastfm2 that it creates itself

This commit is contained in:
Jeff Mitchell
2011-05-01 10:27:43 -04:00
parent e8f2eedcb9
commit 7f7c55a293

View File

@@ -26,9 +26,12 @@
#include <QLocale> #include <QLocale>
#include <QStringList> #include <QStringList>
#include <QThread> #include <QThread>
#include <QMutex>
#include <QUrl> #include <QUrl>
static QMap< QThread*, QNetworkAccessManager* > threadNamMap; static QMap< QThread*, QNetworkAccessManager* > threadNamHash;
static QMap< QThread*, bool > ourNamHash;
static QMutex namAccessMutex;
QString QString
lastfm::ws::host() lastfm::ws::host()
@@ -193,29 +196,33 @@ lastfm::ws::parse( QNetworkReply* reply ) throw( ParseError )
QNetworkAccessManager* QNetworkAccessManager*
lastfm::nam() lastfm::nam()
{ {
QMutexLocker l( &namAccessMutex );
QThread* thread = QThread::currentThread(); QThread* thread = QThread::currentThread();
if ( !threadNamMap.contains( thread ) ) if ( !threadNamHash.contains( thread ) )
{ {
NetworkAccessManager* newNam = new NetworkAccessManager(); NetworkAccessManager* newNam = new NetworkAccessManager();
threadNamMap[thread] = newNam; threadNamHash[thread] = newNam;
ourNamHash[thread] = true;
return newNam; return newNam;
} }
return threadNamMap[thread]; return threadNamHash[thread];
} }
void void
lastfm::setNetworkAccessManager( QNetworkAccessManager* nam ) lastfm::setNetworkAccessManager( QNetworkAccessManager* nam )
{ {
if ( !nam )
return;
QMutexLocker l( &namAccessMutex );
QThread* thread = QThread::currentThread(); QThread* thread = QThread::currentThread();
if ( threadNamMap.contains( thread ) ) if ( threadNamHash.contains( thread ) && ourNamHash.contains( thread ) && ourNamHash[thread] )
{ delete threadNamHash[thread];
delete threadNamMap[thread];
threadNamMap[thread] = 0;
}
threadNamMap[thread] = nam; threadNamHash[thread] = nam;
ourNamHash[thread] = false;
} }