From 03115ed64d916b94c52275fe0b329bd817d4ce94 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 2 May 2020 20:21:35 +0200 Subject: Refactoring: size_t type conversions and QList in DotManager --- src/arguments.h | 2 +- src/commentcnv.l | 2 +- src/doctokenizer.l | 2 +- src/dot.cpp | 51 ++++++++++++++++++++++++++++----------------------- src/dot.h | 4 ++-- src/dotrunner.cpp | 10 +++++++++- src/dotrunner.h | 6 +++--- src/doxygen.cpp | 8 ++++++-- src/linkedmap.h | 4 ++-- src/membername.h | 4 ++-- src/section.h | 2 +- src/util.cpp | 2 +- 12 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/arguments.h b/src/arguments.h index 892de92..181a8d3 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -90,7 +90,7 @@ class ArgumentList const_iterator cbegin() const { return m_args.cbegin(); } const_iterator cend() const { return m_args.cend(); } bool empty() const { return m_args.empty(); } - int size() const { return m_args.size(); } + size_t size() const { return m_args.size(); } void clear() { m_args.clear(); } void push_back(const Argument &a) { m_args.push_back(a); } Argument &back() { return m_args.back(); } diff --git a/src/commentcnv.l b/src/commentcnv.l index 63ecaaf..e05634a 100644 --- a/src/commentcnv.l +++ b/src/commentcnv.l @@ -71,7 +71,7 @@ struct commentcnvYY_state { BufStr * inBuf = 0; BufStr * outBuf = 0; - int inBufPos = 0; + yy_size_t inBufPos = 0; int col = 0; int blockHeadCol = 0; bool mlBrief = FALSE; diff --git a/src/doctokenizer.l b/src/doctokenizer.l index de7d162..7f3fbc9 100644 --- a/src/doctokenizer.l +++ b/src/doctokenizer.l @@ -55,7 +55,7 @@ // context for tokenizer phase static int g_commentState; TokenInfo *g_token = 0; -static int g_inputPos = 0; +static yy_size_t g_inputPos = 0; static const char *g_inputString; static QCString g_fileName; static bool g_insidePre; diff --git a/src/dot.cpp b/src/dot.cpp index acf4db9..675ead6 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -83,6 +83,12 @@ DotManager *DotManager::instance() return m_theInstance; } +void DotManager::deleteInstance() +{ + delete m_theInstance; + m_theInstance=0; +} + DotManager::DotManager() : m_runners(), m_filePatchers() { m_queue = new DotRunnerQueue; @@ -92,18 +98,17 @@ DotManager::DotManager() : m_runners(), m_filePatchers() { for (i=0;i thread = std::make_unique(m_queue); thread->start(); if (thread->isRunning()) { - m_workers.append(thread); + m_workers.push_back(std::move(thread)); } else // no more threads available! { - delete thread; } } - ASSERT(m_workers.count()>0); + ASSERT(m_workers.size()>0); } } @@ -140,7 +145,7 @@ DotFilePatcher *DotManager::createFilePatcher(const std::string &fileName) auto patcher = m_filePatchers.find(fileName); if (patcher != m_filePatchers.end()) return &(patcher->second); - + auto rv = m_filePatchers.emplace(fileName, fileName.c_str()); assert(rv.second); return &(rv.first->second); @@ -148,20 +153,20 @@ DotFilePatcher *DotManager::createFilePatcher(const std::string &fileName) bool DotManager::run() const { - uint numDotRuns = m_runners.size(); - uint numFilePatchers = m_filePatchers.size(); + size_t numDotRuns = m_runners.size(); + size_t numFilePatchers = m_filePatchers.size(); if (numDotRuns+numFilePatchers>1) { - if (m_workers.count()==0) + if (m_workers.size()==0) { msg("Generating dot graphs in single threaded mode...\n"); } else { - msg("Generating dot graphs using %d parallel threads...\n",QMIN(numDotRuns+numFilePatchers,m_workers.count())); + msg("Generating dot graphs using %zu parallel threads...\n",QMIN(numDotRuns+numFilePatchers,m_workers.size())); } } - int i=1; + size_t i=1; bool setPath=FALSE; if (Config_getBool(GENERATE_HTML)) @@ -186,12 +191,12 @@ bool DotManager::run() const } Portable::sysTimerStart(); // fill work queue with dot operations - int prev=1; - if (m_workers.count()==0) // no threads to work with + size_t prev=1; + if (m_workers.size()==0) // no threads to work with { for (auto & dr : m_runners) { - msg("Running dot for graph %d/%d\n",prev,numDotRuns); + msg("Running dot for graph %zu/%zu\n",prev,numDotRuns); dr.second->run(); prev++; } @@ -203,28 +208,28 @@ bool DotManager::run() const m_queue->enqueue(dr.second.get()); } // wait for the queue to become empty - while ((i=m_queue->count())>0) + while ((i=m_queue->size())>0) { i = numDotRuns - i; while (i>=prev) { - msg("Running dot for graph %d/%d\n",prev,numDotRuns); + msg("Running dot for graph %zu/%zu\n",prev,numDotRuns); prev++; } Portable::sleep(100); } - while ((int)numDotRuns>=prev) + while (numDotRuns>=prev) { - msg("Running dot for graph %d/%d\n",prev,numDotRuns); + msg("Running dot for graph %zu/%zu\n",prev,numDotRuns); prev++; } // signal the workers we are done - for (i=0;i<(int)m_workers.count();i++) + for (i=0;ienqueue(0); // add terminator for each worker } // wait for the workers to finish - for (i=0;i<(int)m_workers.count();i++) + for (i=0;iwait(); } @@ -239,13 +244,13 @@ bool DotManager::run() const i=1; // since patching the svg files may involve patching the header of the SVG // (for zoomable SVGs), and patching the .html files requires reading that - // header after the SVG is patched, we first process the .svg files and - // then the other files. + // header after the SVG is patched, we first process the .svg files and + // then the other files. for (auto & fp : m_filePatchers) { if (fp.second.isSVGFile()) { - msg("Patching output file %d/%d\n",i,numFilePatchers); + msg("Patching output file %zu/%zu\n",i,numFilePatchers); if (!fp.second.run()) return FALSE; i++; } @@ -254,7 +259,7 @@ bool DotManager::run() const { if (!fp.second.isSVGFile()) { - msg("Patching output file %d/%d\n",i,numFilePatchers); + msg("Patching output file %zu/%zu\n",i,numFilePatchers); if (!fp.second.run()) return FALSE; i++; } diff --git a/src/dot.h b/src/dot.h index 3c9af66..d14c38a 100644 --- a/src/dot.h +++ b/src/dot.h @@ -16,7 +16,6 @@ #ifndef DOT_H #define DOT_H -#include #include #include @@ -35,6 +34,7 @@ class DotManager { public: static DotManager *instance(); + static void deleteInstance(); DotRunner* createRunner(const std::string& absDotName, const std::string& md5Hash); DotFilePatcher *createFilePatcher(const std::string &fileName); bool run() const; @@ -47,7 +47,7 @@ class DotManager std::map m_filePatchers; static DotManager *m_theInstance; DotRunnerQueue *m_queue; - QList m_workers; + std::vector< std::unique_ptr > m_workers; }; void writeDotGraphFromFile(const char *inFile,const char *outDir, diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index c9ff284..8cf09fa 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -272,7 +272,7 @@ DotRunner *DotRunnerQueue::dequeue() return result; } -uint DotRunnerQueue::count() const +size_t DotRunnerQueue::size() const { std::lock_guard locker(m_mutex); return m_queue.size(); @@ -285,6 +285,14 @@ DotWorkerThread::DotWorkerThread(DotRunnerQueue *queue) { } +DotWorkerThread::~DotWorkerThread() +{ + if (isRunning()) + { + wait(); + } +} + void DotWorkerThread::run() { DotRunner *runner; diff --git a/src/dotrunner.h b/src/dotrunner.h index 555ea78..1b54617 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -16,7 +16,6 @@ #ifndef DOTRUNNER_H #define DOTRUNNER_H -#include //uint #include #include #include @@ -72,7 +71,7 @@ class DotRunnerQueue public: void enqueue(DotRunner *runner); DotRunner *dequeue(); - uint count() const; + size_t size() const; private: std::condition_variable m_bufferNotEmpty; std::queue m_queue; @@ -80,10 +79,11 @@ class DotRunnerQueue }; /** Worker thread to execute a dot run */ -class DotWorkerThread +class DotWorkerThread { public: DotWorkerThread(DotRunnerQueue *queue); + ~DotWorkerThread(); void run(); void start(); bool isRunning() { return m_thread && m_thread->joinable(); } diff --git a/src/doxygen.cpp b/src/doxygen.cpp index fb82bb2..0728d8f 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -4704,7 +4704,7 @@ static void computeClassRelations() { findBaseClassesForClass(root,cd,cd,cd,DocumentedOnly,FALSE); } - int numMembers = cd ? cd->memberNameInfoLinkedMap().size() : 0; + size_t numMembers = cd ? cd->memberNameInfoLinkedMap().size() : 0; if ((cd==0 || (!cd->hasDocumentation() && !cd->isReference())) && numMembers>0 && bName.right(2)!="::") { @@ -8978,8 +8978,10 @@ static void generateDiskNames() // as the common prefix between the first and last entry const FileEntry &first = fileEntries[0]; const FileEntry &last = fileEntries[size-1]; + int first_path_size = static_cast(first.path.size()); + int last_path_size = static_cast(last.path.size()); int j=0; - for (size_t i=0;isecond.data()+scope.right(scope.length()-i); - i=it->second.length(); + i=static_cast(it->second.length()); } } if (i>0 && ns==scope.left(i)) break; -- cgit v0.12