# HG changeset patch # User Chris Cannam # Date 1424943848 0 # Node ID 780959a4fe23619a2efdfaaa2414e9f3ec18045f # Parent 3a48b22fed4873d2edf1826f1c1fe1b5f77ed020# Parent 344c9ea901812553a087da7fecbf5d3596257fa4 Update and merge diff -r 344c9ea90181 -r 780959a4fe23 data/fileio/FileSource.cpp --- a/data/fileio/FileSource.cpp Wed Feb 18 12:08:17 2015 +0000 +++ b/data/fileio/FileSource.cpp Thu Feb 26 09:44:08 2015 +0000 @@ -32,7 +32,7 @@ #include -//#define DEBUG_FILE_SOURCE 1 +#define DEBUG_FILE_SOURCE 1 int FileSource::m_count = 0; @@ -51,8 +51,11 @@ #ifdef DEBUG_FILE_SOURCE static int extantCount = 0; +static int threadCount = 0; static std::map urlExtantCountMap; +static QMutex countMutex; static void incCount(QString url) { + QMutexLocker locker(&countMutex); ++extantCount; if (urlExtantCountMap.find(url) == urlExtantCountMap.end()) { urlExtantCountMap[url] = 1; @@ -62,10 +65,26 @@ cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl; } static void decCount(QString url) { + QMutexLocker locker(&countMutex); --extantCount; --urlExtantCountMap[url]; cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl; } +void +FileSource::debugReport() +{ + QMutexLocker locker(&countMutex); + cerr << "\nFileSource::debugReport: Have " << extantCount << " FileSource object(s) extant across " << threadCount << " thread(s)" << endl; + cerr << "URLs by extant count:" << endl; + cerr << "Count | URL" << endl; + for (std::map::const_iterator i = urlExtantCountMap.begin(); + i != urlExtantCountMap.end(); ++i) { + cerr << i->second << " | " << i->first << endl; + } + cerr << "FileSource::debugReport done\n" << endl; +} +#else +void FileSource::debugReport() { } #endif static QThreadStorage nms; @@ -268,13 +287,6 @@ void FileSource::init() { - { // check we have a QNetworkAccessManager - QMutexLocker locker(&m_mapMutex); - if (!nms.hasLocalData()) { - nms.setLocalData(new QNetworkAccessManager()); - } - } - if (isResource()) { #ifdef DEBUG_FILE_SOURCE cerr << "FileSource::init: Is a resource" << endl; @@ -463,6 +475,16 @@ QString("%1, */*").arg(m_preferredContentType).toLatin1()); } + { // check we have a QNetworkAccessManager + QMutexLocker locker(&m_mapMutex); + if (!nms.hasLocalData()) { +#ifdef DEBUG_FILE_SOURCE + ++threadCount; +#endif + nms.setLocalData(new QNetworkAccessManager()); + } + } + m_reply = nms.localData()->get(req); connect(m_reply, SIGNAL(readyRead()), diff -r 344c9ea90181 -r 780959a4fe23 data/fileio/FileSource.h --- a/data/fileio/FileSource.h Wed Feb 18 12:08:17 2015 +0000 +++ b/data/fileio/FileSource.h Thu Feb 26 09:44:08 2015 +0000 @@ -195,6 +195,13 @@ */ static bool canHandleScheme(QUrl url); + /** + * Print some stats, if FileSource was compiled with debugging. + * It's safe to leave a call to this function in release code, as + * long as FileSource itself is compiled with release flags. + */ + static void debugReport(); + signals: /** * Emitted during URL retrieval, when the retrieval progress