changeset 529:993e0a4f1343

* Try to avoid leaving output files open after completion
author Chris Cannam
date Tue, 20 Jan 2009 18:10:31 +0000
parents 57857a57a03a
children 1d3fc01edc03
files data/fileio/FileSource.cpp
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/FileSource.cpp	Fri Jan 16 15:12:23 2009 +0000
+++ b/data/fileio/FileSource.cpp	Tue Jan 20 18:10:31 2009 +0000
@@ -47,6 +47,25 @@
 QMutex
 FileSource::m_mapMutex;
 
+#ifdef DEBUG_FILE_SOURCE
+static int extantCount = 0;
+static std::map<QString, int> urlExtantCountMap;
+static void incCount(QString url) {
+    ++extantCount;
+    if (urlExtantCountMap.find(url) == urlExtantCountMap.end()) {
+        urlExtantCountMap[url] = 1;
+    } else {
+        ++urlExtantCountMap[url];
+    }
+    std::cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << std::endl;
+}
+static void decCount(QString url) {
+    --extantCount;
+    --urlExtantCountMap[url];
+    std::cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << std::endl;
+}
+#endif
+
 FileSource::FileSource(QString fileOrUrl, ProgressReporter *reporter,
                        QString preferredContentType) :
     m_url(fileOrUrl),
@@ -64,6 +83,7 @@
 {
 #ifdef DEBUG_FILE_SOURCE
     std::cerr << "FileSource::FileSource(" << fileOrUrl.toStdString() << ")" << std::endl;
+    incCount(m_url.toString());
 #endif
 
     if (!canHandleScheme(m_url)) {
@@ -132,6 +152,7 @@
 {
 #ifdef DEBUG_FILE_SOURCE
     std::cerr << "FileSource::FileSource(" << url.toString().toStdString() << ") [as url]" << std::endl;
+    incCount(m_url.toString());
 #endif
 
     if (!canHandleScheme(m_url)) {
@@ -163,6 +184,7 @@
 {
 #ifdef DEBUG_FILE_SOURCE
     std::cerr << "FileSource::FileSource(" << m_url.toString().toStdString() << ") [copy ctor]" << std::endl;
+    incCount(m_url.toString());
 #endif
 
     if (!canHandleScheme(m_url)) {
@@ -207,6 +229,7 @@
 {
 #ifdef DEBUG_FILE_SOURCE
     std::cerr << "FileSource(" << m_url.toString().toStdString() << ")::~FileSource" << std::endl;
+    decCount(m_url.toString());
 #endif
 
     cleanup();
@@ -597,6 +620,10 @@
             if (newUrl != m_url) {
                 cleanup();
                 deleteCacheFile();
+#ifdef DEBUG_FILE_SOURCE
+                decCount(m_url.toString());
+                incCount(newUrl.toString());
+#endif
                 m_url = newUrl;
                 m_localFile = 0;
                 m_lastStatus = 0;