From cf5e0a3dbd3a31c2314e58e55bbdff66b3f49876 Mon Sep 17 00:00:00 2001 From: albert-github Date: Wed, 18 Mar 2020 13:32:02 +0100 Subject: Tcl has a problem with a case statement with just {} inside the switch statement (#7643) In case we have a (reduced) case like: ``` ## ::tkcon::Init - inits tkcon proc ::tkcon::Init {} { switch -glob -- $arg { -root { set PRIV(root) $val } -font { set OPT(font) $val } -rcfile {} } } ``` and a default doxygen configuration file, doxygen will crash in the tcl scanner as the `{}` results in an empty string. Some notes, crash only happens when compilation for 'Release; or 'RelWithDebInfo' as 'CMAKE_BUILD_TYPE'. (Found by Fossies for magic 8.2.195). --- src/tclscanner.l | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tclscanner.l b/src/tclscanner.l index 10aba97..2e15fc5 100644 --- a/src/tclscanner.l +++ b/src/tclscanner.l @@ -1173,6 +1173,7 @@ tcl_inf("line=%d type=%d '%s'\n",tcl.line_body0,type,content.data()); myScan->type[0] = type; break; case '?': + if (content.isEmpty()) break; if (content[0]=='"' && content[content.length()-1]=='"') myScan->type[0]='"'; if (content[0]=='{' && content[content.length()-1]=='}') myScan->type[0]='{'; if (content[0]=='[' && content[content.length()-1]==']') myScan->type[0]='['; -- cgit v0.12 From 110cb591c076f84b6dee49b3fa2a1ebc107f7945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 18:51:12 +0100 Subject: Replace qqueue with std::queue --- src/dotrunner.cpp | 9 +++++---- src/dotrunner.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index fc9f85c..208250a 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -257,26 +257,27 @@ error: void DotRunnerQueue::enqueue(DotRunner *runner) { QMutexLocker locker(&m_mutex); - m_queue.enqueue(runner); + m_queue.push(runner); m_bufferNotEmpty.wakeAll(); } DotRunner *DotRunnerQueue::dequeue() { QMutexLocker locker(&m_mutex); - while (m_queue.isEmpty()) + while (m_queue.empty()) { // wait until something is added to the queue m_bufferNotEmpty.wait(&m_mutex); } - DotRunner *result = m_queue.dequeue(); + DotRunner *result = m_queue.front(); + m_queue.pop(); return result; } uint DotRunnerQueue::count() const { QMutexLocker locker(&m_mutex); - return m_queue.count(); + return m_queue.size(); } //-------------------------------------------------------------------- diff --git a/src/dotrunner.h b/src/dotrunner.h index 1b68c18..48b3dcb 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -20,7 +20,7 @@ #include "qlist.h" #include "qwaitcondition.h" #include "qthread.h" -#include "qqueue.h" +#include #include "qmutex.h" /** Minimal constant string class that is thread safe, once initialized. */ @@ -115,7 +115,7 @@ class DotRunnerQueue uint count() const; private: QWaitCondition m_bufferNotEmpty; - QQueue m_queue; + std::queue m_queue; mutable QMutex m_mutex; }; -- cgit v0.12 From e8f0640e7e80351de68b40b5114f71fe94dc5fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 19:52:44 +0100 Subject: Replace QMutex and condition QWaitCondition with std:: --- src/dotrunner.cpp | 17 ++++++++--------- src/dotrunner.h | 7 +++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index 208250a..a42c242 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -256,19 +256,18 @@ error: void DotRunnerQueue::enqueue(DotRunner *runner) { - QMutexLocker locker(&m_mutex); + std::lock_guard locker(m_mutex); m_queue.push(runner); - m_bufferNotEmpty.wakeAll(); + m_bufferNotEmpty.notify_all(); } DotRunner *DotRunnerQueue::dequeue() { - QMutexLocker locker(&m_mutex); - while (m_queue.empty()) - { - // wait until something is added to the queue - m_bufferNotEmpty.wait(&m_mutex); - } + std::unique_lock locker(m_mutex); + + // wait until something is added to the queue + m_bufferNotEmpty.wait(locker, [this]() {return !m_queue.empty(); }); + DotRunner *result = m_queue.front(); m_queue.pop(); return result; @@ -276,7 +275,7 @@ DotRunner *DotRunnerQueue::dequeue() uint DotRunnerQueue::count() const { - QMutexLocker locker(&m_mutex); + std::lock_guard locker(m_mutex); return m_queue.size(); } diff --git a/src/dotrunner.h b/src/dotrunner.h index 48b3dcb..2fa0b61 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -18,10 +18,9 @@ #include "qcstring.h" #include "qlist.h" -#include "qwaitcondition.h" #include "qthread.h" #include -#include "qmutex.h" +#include /** Minimal constant string class that is thread safe, once initialized. */ class DotConstString @@ -114,9 +113,9 @@ class DotRunnerQueue DotRunner *dequeue(); uint count() const; private: - QWaitCondition m_bufferNotEmpty; + std::condition_variable m_bufferNotEmpty; std::queue m_queue; - mutable QMutex m_mutex; + mutable std::mutex m_mutex; }; /** Worker thread to execute a dot run */ -- cgit v0.12 From 00e79b8621b00f72ea56f81b1c4df9eae4ed9252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 20:01:31 +0100 Subject: Replace qlist with std::vector --- src/dotrunner.cpp | 36 ++++++++++++++++-------------------- src/dotrunner.h | 4 ++-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index a42c242..21967cb 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -151,22 +151,20 @@ DotRunner::DotRunner(const QCString& absDotName, const QCString& md5Hash) , m_dotExe(Config_getString(DOT_PATH)+"dot") , m_cleanUp(Config_getBool(DOT_CLEANUP)) { - m_jobs.setAutoDelete(TRUE); } void DotRunner::addJob(const char *format,const char *output) { - QListIterator li(m_jobs); - DotJob *s; - for (li.toFirst(); (s = li.current()); ++li) + + for (auto& s: m_jobs) { - if (qstrcmp(s->format.data(), format) != 0) continue; - if (qstrcmp(s->output.data(), output) != 0) continue; + if (qstrcmp(s.format.data(), format) != 0) continue; + if (qstrcmp(s.output.data(), output) != 0) continue; // we have this job already return; } QCString args = QCString("-T")+format+" -o \""+output+"\""; - m_jobs.append(new DotJob(format, output, args)); + m_jobs.emplace_back(format, output, args); } QCString getBaseNameOfOutput(QCString const& output) @@ -181,48 +179,46 @@ bool DotRunner::run() int exitCode=0; QCString dotArgs; - QListIterator li(m_jobs); - DotJob *s; // create output if (Config_getBool(DOT_MULTI_TARGETS)) { dotArgs=QCString("\"")+m_file.data()+"\""; - for (li.toFirst();(s=li.current());++li) + for (auto& s: m_jobs) { dotArgs+=' '; - dotArgs+=s->args.data(); + dotArgs+=s.args.data(); } if ((exitCode=Portable::system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error; } else { - for (li.toFirst();(s=li.current());++li) + for (auto& s : m_jobs) { - dotArgs=QCString("\"")+m_file.data()+"\" "+s->args.data(); + dotArgs=QCString("\"")+m_file.data()+"\" "+s.args.data(); if ((exitCode=Portable::system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error; } } // check output // As there should be only one pdf file be generated, we don't need code for regenerating multiple pdf files in one call - for (li.toFirst();(s=li.current());++li) + for (auto& s : m_jobs) { - if (qstrncmp(s->format.data(), "pdf", 3) == 0) + if (qstrncmp(s.format.data(), "pdf", 3) == 0) { int width=0,height=0; - if (!readBoundingBox(s->output.data(),&width,&height,FALSE)) goto error; + if (!readBoundingBox(s.output.data(),&width,&height,FALSE)) goto error; if ((width > MAX_LATEX_GRAPH_SIZE) || (height > MAX_LATEX_GRAPH_SIZE)) { - if (!resetPDFSize(width,height,getBaseNameOfOutput(s->output.data()))) goto error; - dotArgs=QCString("\"")+m_file.data()+"\" "+s->args.data(); + if (!resetPDFSize(width,height,getBaseNameOfOutput(s.output.data()))) goto error; + dotArgs=QCString("\"")+m_file.data()+"\" "+s.args.data(); if ((exitCode=Portable::system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error; } } - if (qstrncmp(s->format.data(), "png", 3) == 0) + if (qstrncmp(s.format.data(), "png", 3) == 0) { - checkPngResult(s->output.data()); + checkPngResult(s.output.data()); } } diff --git a/src/dotrunner.h b/src/dotrunner.h index 2fa0b61..052d5f7 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -17,8 +17,8 @@ #define DOTRUNNER_H #include "qcstring.h" -#include "qlist.h" #include "qthread.h" +#include #include #include @@ -101,7 +101,7 @@ class DotRunner DotConstString m_md5Hash; DotConstString m_dotExe; bool m_cleanUp; - QList m_jobs; + std::vector m_jobs; }; /** Queue of dot jobs to run. */ -- cgit v0.12 From 5a6f35b0de84350b867e06b3eb85622c4cface37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 20:56:59 +0100 Subject: Replace QThread with std::thread --- src/dotrunner.cpp | 6 ++++++ src/dotrunner.h | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index 21967cb..28c49cd 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -289,4 +289,10 @@ void DotWorkerThread::run() { runner->run(); } +} + +void DotWorkerThread::start() +{ + assert(!m_thread); + m_thread = std::make_unique(&DotWorkerThread::run, this); } diff --git a/src/dotrunner.h b/src/dotrunner.h index 052d5f7..e08ae6f 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -17,10 +17,11 @@ #define DOTRUNNER_H #include "qcstring.h" -#include "qthread.h" +#include #include #include #include +#include /** Minimal constant string class that is thread safe, once initialized. */ class DotConstString @@ -119,12 +120,16 @@ class DotRunnerQueue }; /** Worker thread to execute a dot run */ -class DotWorkerThread : public QThread +class DotWorkerThread { public: DotWorkerThread(DotRunnerQueue *queue); void run(); + void start(); + bool isRunning() { return m_thread && m_thread->joinable(); } + void wait() { m_thread->join(); } private: + std::unique_ptr m_thread; DotRunnerQueue *m_queue; }; -- cgit v0.12 From d47343e2a932c2b7834850ed903943c635f7bd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 21:05:05 +0100 Subject: Fixup condition-variable and mutex --- src/dotrunner.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dotrunner.h b/src/dotrunner.h index e08ae6f..65bc543 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -21,6 +21,7 @@ #include #include #include +#include #include /** Minimal constant string class that is thread safe, once initialized. */ -- cgit v0.12 From 593d0591487c65d5d51246e8e6ea93c83518f6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 21:23:35 +0100 Subject: Remove DotConstString and replace by std::string Whatever the idea of creating DotConstString was, probably creating copy-free Strings, it is not used anymore as each job gets its own copy anyway. --- src/dotrunner.cpp | 6 ++--- src/dotrunner.h | 67 ++++++++++++------------------------------------------- 2 files changed, 17 insertions(+), 56 deletions(-) diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index 28c49cd..d6dd1fe 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -146,8 +146,8 @@ bool DotRunner::readBoundingBox(const char *fileName,int *width,int *height,bool //--------------------------------------------------------------------------------- DotRunner::DotRunner(const QCString& absDotName, const QCString& md5Hash) - : m_file(absDotName) - , m_md5Hash(md5Hash) + : m_file(absDotName.data()) + , m_md5Hash(md5Hash.data()) , m_dotExe(Config_getString(DOT_PATH)+"dot") , m_cleanUp(Config_getBool(DOT_CLEANUP)) { @@ -230,7 +230,7 @@ bool DotRunner::run() } // create checksum file - if (!m_md5Hash.isEmpty()) + if (!m_md5Hash.empty()) { QCString md5Name = getBaseNameOfOutput(m_file.data()) + ".md5"; FILE *f = Portable::fopen(md5Name,"w"); diff --git a/src/dotrunner.h b/src/dotrunner.h index 65bc543..fb653dc 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -16,7 +16,8 @@ #ifndef DOTRUNNER_H #define DOTRUNNER_H -#include "qcstring.h" +#include +#include #include #include #include @@ -24,59 +25,19 @@ #include #include -/** Minimal constant string class that is thread safe, once initialized. */ -class DotConstString -{ - public: - DotConstString() { m_str=0;} - ~DotConstString() { delete[] m_str;} - DotConstString(char const* s) : m_str(0) { set(s); } - DotConstString(const QCString &s) : m_str(0) { set(s); } - DotConstString(const DotConstString &s) : m_str(0) { set(s.data()); } - const char *data() const { return m_str; } - bool isEmpty() const { return m_str==0 || m_str[0]=='\0'; } - - private: - void set(char const* s) - { - delete[] m_str; - m_str=0; - if (s) - { - m_str=new char[strlen(s) + 1]; - qstrcpy(m_str,s); - } - } - - void set(const QCString &s) - { - delete[] m_str; - m_str=0; - if (!s.isEmpty()) - { - m_str=new char[s.length()+1]; - qstrcpy(m_str,s.data()); - } - } - - DotConstString &operator=(const DotConstString &); - - char *m_str; -}; - /** Helper class to run dot from doxygen from multiple threads. */ class DotRunner { public: struct DotJob { - DotJob(const DotConstString & format, - const DotConstString & output, - const DotConstString & args) - : format(format), output(output), args(args) {} - DotConstString format; - DotConstString output; - DotConstString args; + DotJob(std::string format, + std::string output, + std::string args) + : format(std::move(format)), output(std::move(output)), args(std::move(args)) {} + std::string format; + std::string output; + std::string args; }; /** Creates a runner for a dot \a file. */ @@ -94,15 +55,15 @@ class DotRunner bool run(); // DotConstString const& getFileName() { return m_file; } - DotConstString const& getMd5Hash() { return m_md5Hash; } + std::string const & getMd5Hash() { return m_md5Hash; } static bool readBoundingBox(const char* fileName, int* width, int* height, bool isEps); private: - DotConstString m_file; - DotConstString m_md5Hash; - DotConstString m_dotExe; - bool m_cleanUp; + std::string m_file; + std::string m_md5Hash; + std::string m_dotExe; + bool m_cleanUp; std::vector m_jobs; }; -- cgit v0.12 From e0fa50b71c74a191a64a2361564a016e6f9c0204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 22:16:17 +0100 Subject: QString -> std::string & QDict -> std::map Replacing QString required replacing the QDict, too. --- src/dot.cpp | 35 +++++++++++++++++------------------ src/dot.h | 6 +++--- src/dotgraph.cpp | 4 ++-- src/dotrunner.cpp | 16 +++++++++------- src/dotrunner.h | 6 +++--- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/dot.cpp b/src/dot.cpp index f26bee4..2e07a78 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -83,9 +83,8 @@ DotManager *DotManager::instance() return m_theInstance; } -DotManager::DotManager() : m_runners(1009), m_filePatchers(1009) +DotManager::DotManager() : m_runners(), m_filePatchers(1009) { - m_runners.setAutoDelete(TRUE); m_filePatchers.setAutoDelete(TRUE); m_queue = new DotRunnerQueue; int i; @@ -114,23 +113,25 @@ DotManager::~DotManager() delete m_queue; } -DotRunner* DotManager::createRunner(const QCString& absDotName, const QCString& md5Hash) +DotRunner* DotManager::createRunner(const std::string &absDotName, const std::string& md5Hash) { - DotRunner * run = m_runners.find(absDotName); - if (run == 0) + DotRunner* rv = nullptr; + auto const runit = m_runners.find(absDotName); + if (runit == m_runners.end()) { - run = new DotRunner(absDotName, md5Hash); - m_runners.insert(absDotName, run); + auto insobj = std::make_unique(absDotName, md5Hash); + rv = insobj.get(); + m_runners.emplace(absDotName, std::move(insobj)); } else { // we have a match - if (md5Hash != QCString(run->getMd5Hash().data())) + if (md5Hash != runit->second->getMd5Hash()) { err("md5 hash does not match for two different runs of %s !\n", absDotName.data()); } } - return run; + return rv; } DotFilePatcher *DotManager::createFilePatcher(const QCString &fileName) @@ -146,7 +147,7 @@ DotFilePatcher *DotManager::createFilePatcher(const QCString &fileName) bool DotManager::run() const { - uint numDotRuns = m_runners.count(); + uint numDotRuns = m_runners.size(); uint numFilePatchers = m_filePatchers.count(); if (numDotRuns+numFilePatchers>1) { @@ -160,7 +161,6 @@ bool DotManager::run() const } } int i=1; - QDictIterator li(m_runners); bool setPath=FALSE; if (Config_getBool(GENERATE_HTML)) @@ -185,22 +185,21 @@ bool DotManager::run() const } Portable::sysTimerStart(); // fill work queue with dot operations - DotRunner *dr; int prev=1; if (m_workers.count()==0) // no threads to work with { - for (li.toFirst();(dr=li.current());++li) + for (auto & dr : m_runners) { msg("Running dot for graph %d/%d\n",prev,numDotRuns); - dr->run(); + dr.second->run(); prev++; } } else // use multiple threads to run instances of dot in parallel { - for (li.toFirst();(dr=li.current());++li) + for (auto & dr: m_runners) { - m_queue->enqueue(dr); + m_queue->enqueue(dr.second.get()); } // wait for the queue to become empty while ((i=m_queue->count())>0) @@ -280,7 +279,7 @@ void writeDotGraphFromFile(const char *inFile,const char *outDir, QCString absImgName = d.absPath().utf8()+"/"+imgName; QCString absOutFile = d.absPath().utf8()+"/"+outFile; - DotRunner dotRun(inFile, QCString()); + DotRunner dotRun(inFile); if (format==GOF_BITMAP) { dotRun.addJob(Config_getEnum(DOT_IMAGE_FORMAT),absImgName); @@ -333,7 +332,7 @@ void writeDotImageMapFromFile(FTextStream &t, QCString imgName = baseName+"."+imgExt; QCString absOutFile = d.absPath().utf8()+"/"+mapName; - DotRunner dotRun(inFile, QCString()); + DotRunner dotRun(inFile.data()); dotRun.addJob(MAP_CMD,absOutFile); dotRun.preventCleanUp(); if (!dotRun.run()) diff --git a/src/dot.h b/src/dot.h index 60f7f26..8f36f30 100644 --- a/src/dot.h +++ b/src/dot.h @@ -17,8 +17,8 @@ #define DOT_H #include -#include #include +#include #include "sortdict.h" @@ -35,7 +35,7 @@ class DotManager { public: static DotManager *instance(); - DotRunner* createRunner(const QCString& absDotName, const QCString& md5Hash); + DotRunner* createRunner(const std::string& absDotName, const std::string& md5Hash); DotFilePatcher *createFilePatcher(const QCString &fileName); bool run() const; @@ -43,7 +43,7 @@ class DotManager DotManager(); virtual ~DotManager(); - QDict m_runners; + std::map> m_runners; SDict m_filePatchers; static DotManager *m_theInstance; DotRunnerQueue *m_queue; diff --git a/src/dotgraph.cpp b/src/dotgraph.cpp index 0bfa712..cdf4f6c 100644 --- a/src/dotgraph.cpp +++ b/src/dotgraph.cpp @@ -186,14 +186,14 @@ bool DotGraph::prepareDotFile() if (m_graphFormat == GOF_BITMAP) { // run dot to create a bitmap image - DotRunner * dotRun = DotManager::instance()->createRunner(absDotName(), sigStr); + DotRunner * dotRun = DotManager::instance()->createRunner(absDotName().data(), sigStr.data()); dotRun->addJob(Config_getEnum(DOT_IMAGE_FORMAT), absImgName()); if (m_generateImageMap) dotRun->addJob(MAP_CMD, absMapName()); } else if (m_graphFormat == GOF_EPS) { // run dot to create a .eps image - DotRunner *dotRun = DotManager::instance()->createRunner(absDotName(), sigStr); + DotRunner *dotRun = DotManager::instance()->createRunner(absDotName().data(), sigStr.data()); if (Config_getBool(USE_PDFLATEX)) { dotRun->addJob("pdf",absImgName()); diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index d6dd1fe..90cc5eb 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -15,6 +15,7 @@ #include "dotrunner.h" +#include "qstring.h" #include "util.h" #include "portable.h" #include "dot.h" @@ -145,7 +146,7 @@ bool DotRunner::readBoundingBox(const char *fileName,int *width,int *height,bool //--------------------------------------------------------------------------------- -DotRunner::DotRunner(const QCString& absDotName, const QCString& md5Hash) +DotRunner::DotRunner(const std::string& absDotName, const std::string& md5Hash) : m_file(absDotName.data()) , m_md5Hash(md5Hash.data()) , m_dotExe(Config_getString(DOT_PATH)+"dot") @@ -153,17 +154,18 @@ DotRunner::DotRunner(const QCString& absDotName, const QCString& md5Hash) { } -void DotRunner::addJob(const char *format,const char *output) + +void DotRunner::addJob(const char *format, const char *output) { for (auto& s: m_jobs) { - if (qstrcmp(s.format.data(), format) != 0) continue; - if (qstrcmp(s.output.data(), output) != 0) continue; + if (s.format != format) continue; + if (s.output != output) continue; // we have this job already return; } - QCString args = QCString("-T")+format+" -o \""+output+"\""; + auto args = std::string ("-T") + format + " -o \"" + output + "\""; m_jobs.emplace_back(format, output, args); } @@ -204,7 +206,7 @@ bool DotRunner::run() // As there should be only one pdf file be generated, we don't need code for regenerating multiple pdf files in one call for (auto& s : m_jobs) { - if (qstrncmp(s.format.data(), "pdf", 3) == 0) + if (s.format.compare(0, 3, "pdf") == 0) { int width=0,height=0; if (!readBoundingBox(s.output.data(),&width,&height,FALSE)) goto error; @@ -216,7 +218,7 @@ bool DotRunner::run() } } - if (qstrncmp(s.format.data(), "png", 3) == 0) + if (s.format.compare(0, 3, "png") == 0) { checkPngResult(s.output.data()); } diff --git a/src/dotrunner.h b/src/dotrunner.h index fb653dc..89eabf8 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -16,7 +16,7 @@ #ifndef DOTRUNNER_H #define DOTRUNNER_H -#include +#include //uint #include #include #include @@ -41,7 +41,7 @@ class DotRunner }; /** Creates a runner for a dot \a file. */ - DotRunner(const QCString& absDotName, const QCString& md5Hash); + DotRunner(const std::string& absDotName, const std::string& md5Hash = std::string()); /** Adds an additional job to the run. * Performing multiple jobs one file can be faster. @@ -49,7 +49,7 @@ class DotRunner void addJob(const char *format,const char *output); /** Prevent cleanup of the dot file (for user provided dot files) */ - void preventCleanUp() { m_cleanUp = FALSE; } + void preventCleanUp() { m_cleanUp = false; } /** Runs dot for all jobs added. */ bool run(); -- cgit v0.12 From 9ab5f68756f1555a805dda5d0215d275d3db8725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Thu, 19 Mar 2020 22:39:12 +0100 Subject: Replace SDict with std::map --- src/dot.cpp | 37 ++++++++++++++++++------------------- src/dot.h | 4 ++-- src/dotgraph.cpp | 8 ++++---- src/dotlegendgraph.cpp | 2 +- src/dotrunner.cpp | 1 + 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/dot.cpp b/src/dot.cpp index 2e07a78..acf4db9 100644 --- a/src/dot.cpp +++ b/src/dot.cpp @@ -83,9 +83,8 @@ DotManager *DotManager::instance() return m_theInstance; } -DotManager::DotManager() : m_runners(), m_filePatchers(1009) +DotManager::DotManager() : m_runners(), m_filePatchers() { - m_filePatchers.setAutoDelete(TRUE); m_queue = new DotRunnerQueue; int i; int dotNumThreads = Config_getInt(DOT_NUM_THREADS); @@ -130,25 +129,27 @@ DotRunner* DotManager::createRunner(const std::string &absDotName, const std::st { err("md5 hash does not match for two different runs of %s !\n", absDotName.data()); } + rv = runit->second.get(); } + assert(rv); return rv; } -DotFilePatcher *DotManager::createFilePatcher(const QCString &fileName) +DotFilePatcher *DotManager::createFilePatcher(const std::string &fileName) { - DotFilePatcher *patcher = m_filePatchers.find(fileName); - if (patcher==0) - { - patcher = new DotFilePatcher(fileName); - m_filePatchers.append(fileName,patcher); - } - return patcher; + 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); } bool DotManager::run() const { uint numDotRuns = m_runners.size(); - uint numFilePatchers = m_filePatchers.count(); + uint numFilePatchers = m_filePatchers.size(); if (numDotRuns+numFilePatchers>1) { if (m_workers.count()==0) @@ -236,27 +237,25 @@ bool DotManager::run() const // patch the output file and insert the maps and figures i=1; - SDict::Iterator di(m_filePatchers); - const DotFilePatcher *fp; // 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. - for (di.toFirst();(fp=di.current());++di) + for (auto & fp : m_filePatchers) { - if (fp->isSVGFile()) + if (fp.second.isSVGFile()) { msg("Patching output file %d/%d\n",i,numFilePatchers); - if (!fp->run()) return FALSE; + if (!fp.second.run()) return FALSE; i++; } } - for (di.toFirst();(fp=di.current());++di) + for (auto& fp : m_filePatchers) { - if (!fp->isSVGFile()) + if (!fp.second.isSVGFile()) { msg("Patching output file %d/%d\n",i,numFilePatchers); - if (!fp->run()) return FALSE; + if (!fp.second.run()) return FALSE; i++; } } diff --git a/src/dot.h b/src/dot.h index 8f36f30..3c9af66 100644 --- a/src/dot.h +++ b/src/dot.h @@ -36,7 +36,7 @@ class DotManager public: static DotManager *instance(); DotRunner* createRunner(const std::string& absDotName, const std::string& md5Hash); - DotFilePatcher *createFilePatcher(const QCString &fileName); + DotFilePatcher *createFilePatcher(const std::string &fileName); bool run() const; private: @@ -44,7 +44,7 @@ class DotManager virtual ~DotManager(); std::map> m_runners; - SDict m_filePatchers; + std::map m_filePatchers; static DotManager *m_theInstance; DotRunnerQueue *m_queue; QList m_workers; diff --git a/src/dotgraph.cpp b/src/dotgraph.cpp index cdf4f6c..e622dd4 100644 --- a/src/dotgraph.cpp +++ b/src/dotgraph.cpp @@ -233,11 +233,11 @@ void DotGraph::generateCode(FTextStream &t) if (m_regenerate) { DotManager::instance()-> - createFilePatcher(absImgName())-> + createFilePatcher(absImgName().data())-> addSVGConversion(m_relPath,FALSE,QCString(),m_zoomable,m_graphId); } int mapId = DotManager::instance()-> - createFilePatcher(m_fileName)-> + createFilePatcher(m_fileName.data())-> addSVGObject(m_baseName,absImgName(),m_relPath); t << "" << endl; } @@ -252,7 +252,7 @@ void DotGraph::generateCode(FTextStream &t) if (m_regenerate || !insertMapFile(t, absMapName(), m_relPath, getMapLabel())) { int mapId = DotManager::instance()-> - createFilePatcher(m_fileName)-> + createFilePatcher(m_fileName.data())-> addMap(absMapName(), m_relPath, m_urlOnly, QCString(), getMapLabel()); t << "" << endl; } @@ -263,7 +263,7 @@ void DotGraph::generateCode(FTextStream &t) if (m_regenerate || !DotFilePatcher::writeVecGfxFigure(t,m_baseName,absBaseName())) { int figId = DotManager::instance()-> - createFilePatcher(m_fileName)-> + createFilePatcher(m_fileName.data())-> addFigure(m_baseName,absBaseName(),FALSE /*TRUE*/); t << endl << "% FIG " << figId << endl; } diff --git a/src/dotlegendgraph.cpp b/src/dotlegendgraph.cpp index 98e1f88..b17a293 100644 --- a/src/dotlegendgraph.cpp +++ b/src/dotlegendgraph.cpp @@ -29,7 +29,7 @@ void DotLegendGraph::writeGraph(const char *path) if (getDotImageExtension()=="svg") { DotManager::instance()-> - createFilePatcher(absBaseName()+Config_getString(HTML_FILE_EXTENSION))-> + createFilePatcher((absBaseName()+Config_getString(HTML_FILE_EXTENSION)).data())-> addSVGObject("graph_legend", absImgName(),QCString()); } } diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index 90cc5eb..db69b30 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -151,6 +151,7 @@ DotRunner::DotRunner(const std::string& absDotName, const std::string& md5Hash) , m_md5Hash(md5Hash.data()) , m_dotExe(Config_getString(DOT_PATH)+"dot") , m_cleanUp(Config_getBool(DOT_CLEANUP)) + , m_jobs() { } -- cgit v0.12 From 475b4d7388cfc408fed097d80521db289c4522b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Fri, 20 Mar 2020 10:11:24 +0100 Subject: Remove last QThread-Reference --- src/configimpl.l | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/configimpl.l b/src/configimpl.l index 055304d..39f60e4 100644 --- a/src/configimpl.l +++ b/src/configimpl.l @@ -33,8 +33,8 @@ #include #include #include -#include - +#include + #include "configimpl.h" #include "version.h" #include "portable.h" @@ -1681,7 +1681,7 @@ void Config::checkAndCorrect() } else if (dotNumThreads<=0) { - dotNumThreads=QMAX(2,QThread::idealThreadCount()+1); + dotNumThreads=QMAX(2,std::thread::hardware_concurrency()+1); } // check dot path -- cgit v0.12 From 739e9c039b6678b0565922f8a38e062cc83fd702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20=27Morty=27=20Str=C3=BCbe?= Date: Fri, 20 Mar 2020 10:20:05 +0100 Subject: Remove thread-related Qt-Code --- qtools/CMakeLists.txt | 8 -- qtools/qmutex.cpp | 95 ---------------- qtools/qmutex.h | 83 -------------- qtools/qmutex_p.h | 90 --------------- qtools/qmutex_unix.cpp | 117 -------------------- qtools/qmutex_win32.cpp | 108 ------------------ qtools/qtextcodec.cpp | 2 +- qtools/qthread.cpp | 86 --------------- qtools/qthread.h | 77 ------------- qtools/qthread_p.h | 85 -------------- qtools/qthread_unix.cpp | 239 ---------------------------------------- qtools/qthread_win32.cpp | 158 -------------------------- qtools/qtools.pro.in | 19 +--- qtools/qwaitcondition.h | 68 ------------ qtools/qwaitcondition_unix.cpp | 134 ---------------------- qtools/qwaitcondition_win32.cpp | 186 ------------------------------- 16 files changed, 4 insertions(+), 1551 deletions(-) delete mode 100644 qtools/qmutex.cpp delete mode 100644 qtools/qmutex.h delete mode 100644 qtools/qmutex_p.h delete mode 100644 qtools/qmutex_unix.cpp delete mode 100644 qtools/qmutex_win32.cpp delete mode 100644 qtools/qthread.cpp delete mode 100644 qtools/qthread.h delete mode 100644 qtools/qthread_p.h delete mode 100644 qtools/qthread_unix.cpp delete mode 100644 qtools/qthread_win32.cpp delete mode 100644 qtools/qwaitcondition.h delete mode 100644 qtools/qwaitcondition_unix.cpp delete mode 100644 qtools/qwaitcondition_win32.cpp diff --git a/qtools/CMakeLists.txt b/qtools/CMakeLists.txt index cc64de1..a7082c7 100644 --- a/qtools/CMakeLists.txt +++ b/qtools/CMakeLists.txt @@ -25,8 +25,6 @@ qstringlist.cpp qcstringlist.cpp qxml.cpp qmap.cpp -qthread.cpp -qmutex.cpp qutfcodec.cpp ) @@ -35,9 +33,6 @@ list(APPEND qtools_src qfile_unix.cpp qdir_unix.cpp qfileinfo_unix.cpp -qthread_unix.cpp -qmutex_unix.cpp -qwaitcondition_unix.cpp ) endif() @@ -46,9 +41,6 @@ list(APPEND qtools_src qfile_win32.cpp qdir_win32.cpp qfileinfo_win32.cpp -qthread_win32.cpp -qmutex_win32.cpp -qwaitcondition_win32.cpp ) endif() diff --git a/qtools/qmutex.cpp b/qtools/qmutex.cpp deleted file mode 100644 index 08a13bc..0000000 --- a/qtools/qmutex.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qglobal.h" - -#include "qmutex.h" -#include "qmutex_p.h" - -QMutex::QMutex() : d(new QMutexPrivate()) -{ -} - -QMutex::~QMutex() -{ - delete d; -} - -void QMutex::lock() -{ - //printf("%p: QMutex::lock(): enter\n",this); - bool isLocked; - isLocked = d->contenders.testAndSet(0, 1); - if (!isLocked) - { - isLocked = d->contenders.fetchAndAdd(1)==0; - if (!isLocked) - { - // didn't get the lock, wait for it - //printf("%p: QMutex::lock(): wait() %d\n",this,(int)d->contenders); - d->wait(); - - // release lock - d->contenders.fetchAndAdd(-1); - } - } - //printf("%p: QMutex::lock(): leave\n",this); -} - -bool QMutex::tryLock() -{ - bool isLocked = d->contenders.testAndSet(0, 1); - return isLocked; -} - -void QMutex::unlock() -{ - //printf("%p: QMutex::unlock(): enter %d\n",this,(int)d->contenders); - if (!d->contenders.testAndSet(1, 0)) - { - //printf("%p: QMutex::unlock(): wakeUp()\n",this); - d->wakeUp(); - } - //printf("%p: QMutex::unlock(): leave\n",this); -} - diff --git a/qtools/qmutex.h b/qtools/qmutex.h deleted file mode 100644 index d3d2ac0..0000000 --- a/qtools/qmutex.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMUTEX_H -#define QMUTEX_H - -#include "qglobal.h" - -class QMutexPrivate; - -class QMutex -{ -public: - QMutex(); - ~QMutex(); - - void lock(); - bool tryLock(); - void unlock(); - -private: - QMutex(const QMutex &); - QMutex &operator=(const QMutex &); - - QMutexPrivate *d; -}; - -class QMutexLocker -{ - public: - QMutexLocker(QMutex *m) : m_mutex(m) - { - m_mutex->lock(); - } - ~QMutexLocker() - { - m_mutex->unlock(); - } - QMutex *mutex() const { return m_mutex; } - - private: - QMutex *m_mutex; -}; - -#endif // QMUTEX_H diff --git a/qtools/qmutex_p.h b/qtools/qmutex_p.h deleted file mode 100644 index a47b407..0000000 --- a/qtools/qmutex_p.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMUTEX_P_H -#define QMUTEX_P_H - -#include "qglobal.h" - -#if defined(_OS_UNIX_) || defined(_OS_MAC_) -#include -#elif defined(_OS_WIN32_) -#include -#endif - -class QAtomicInt -{ - public: - QAtomicInt(int v=0) : m_value(v) {} - bool testAndSet(int expectedValue,int newValue); - int fetchAndAdd(int valueToAdd); - operator int () const { return m_value; } - bool operator==(int value) const { return m_value == value; } - bool operator!=(int value) const { return m_value != value; } - bool operator!() const { return m_value == 0; } - - private: - volatile int m_value; -}; - -class QMutexPrivate -{ -public: - QMutexPrivate(); - ~QMutexPrivate(); - - void wait(); - void wakeUp(); - - QAtomicInt contenders; - -#if defined(_OS_UNIX_) || defined(_OS_MAC_) - volatile bool wakeup; - pthread_mutex_t mutex; - pthread_cond_t cond; -#elif defined(_OS_WIN32_) - HANDLE event; -#else -#error "unsupported platform" -#endif -}; - -#endif // QMUTEX_P_H diff --git a/qtools/qmutex_unix.cpp b/qtools/qmutex_unix.cpp deleted file mode 100644 index 4fe9a58..0000000 --- a/qtools/qmutex_unix.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include "qglobal.h" -#include "qmutex.h" -#include "qmutex_p.h" - -static pthread_mutex_t qAtomicMutex = PTHREAD_MUTEX_INITIALIZER; - -static void report_error(int code, const char *where, const char *what) -{ - if (code != 0) - qWarning("%s: %s failure: %d", where, what, code); -} - - -QMutexPrivate::QMutexPrivate() - : contenders(0), wakeup(FALSE) -{ - report_error(pthread_mutex_init(&mutex, NULL), "QMutex", "mutex init"); - report_error(pthread_cond_init(&cond, NULL), "QMutex", "cv init"); -} - -QMutexPrivate::~QMutexPrivate() -{ - report_error(pthread_cond_destroy(&cond), "QMutex", "cv destroy"); - report_error(pthread_mutex_destroy(&mutex), "QMutex", "mutex destroy"); -} - -void QMutexPrivate::wait() -{ - report_error(pthread_mutex_lock(&mutex), "QMutex::lock", "mutex lock"); - int errorCode = 0; - while (!wakeup) - { - errorCode = pthread_cond_wait(&cond, &mutex); - if (errorCode) - { - report_error(errorCode, "QMutex::lock()", "cv wait"); - } - } - wakeup = FALSE; - report_error(pthread_mutex_unlock(&mutex), "QMutex::lock", "mutex unlock"); -} - -void QMutexPrivate::wakeUp() -{ - report_error(pthread_mutex_lock(&mutex), "QMutex::unlock", "mutex lock"); - wakeup = TRUE; - report_error(pthread_cond_signal(&cond), "QMutex::unlock", "cv signal"); - report_error(pthread_mutex_unlock(&mutex), "QMutex::unlock", "mutex unlock"); -} - -bool QAtomicInt::testAndSet(int expectedValue,int newValue) -{ - bool returnValue = false; - pthread_mutex_lock(&qAtomicMutex); - if (m_value == expectedValue) - { - m_value = newValue; - returnValue = true; - } - pthread_mutex_unlock(&qAtomicMutex); - return returnValue; -} - -int QAtomicInt::fetchAndAdd(int valueToAdd) -{ - int returnValue; - pthread_mutex_lock(&qAtomicMutex); - returnValue = m_value; - m_value += valueToAdd; - pthread_mutex_unlock(&qAtomicMutex); - return returnValue; -} - diff --git a/qtools/qmutex_win32.cpp b/qtools/qmutex_win32.cpp deleted file mode 100644 index 2d662ea..0000000 --- a/qtools/qmutex_win32.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qmutex.h" -#include "qmutex_p.h" - -QMutexPrivate::QMutexPrivate() - : contenders(0) -{ - event = CreateEvent(0, FALSE, FALSE, 0); - if (!event) - qWarning("QMutexPrivate::QMutexPrivate: Cannot create event"); -} - -QMutexPrivate::~QMutexPrivate() -{ - CloseHandle(event); -} - -void QMutexPrivate::wait() -{ - WaitForSingleObject(event, INFINITE); -} - -void QMutexPrivate::wakeUp() -{ - SetEvent(event); -} - -//---------------------------------------------------------------------- - -class QCriticalSection -{ - public: - QCriticalSection() { InitializeCriticalSection(§ion); } - ~QCriticalSection() { DeleteCriticalSection(§ion); } - void lock() { EnterCriticalSection(§ion); } - void unlock() { LeaveCriticalSection(§ion); } - - private: - CRITICAL_SECTION section; -}; - -static QCriticalSection qAtomicCriticalSection; - -bool QAtomicInt::testAndSet(int expectedValue,int newValue) -{ - bool returnValue = false; - qAtomicCriticalSection.lock(); - if (m_value == expectedValue) - { - m_value = newValue; - returnValue = true; - } - qAtomicCriticalSection.unlock(); - return returnValue; -} - -int QAtomicInt::fetchAndAdd(int valueToAdd) -{ - int returnValue; - qAtomicCriticalSection.lock(); - returnValue = m_value; - m_value += valueToAdd; - qAtomicCriticalSection.unlock(); - return returnValue; -} - diff --git a/qtools/qtextcodec.cpp b/qtools/qtextcodec.cpp index 8ce266d..13c3d51 100644 --- a/qtools/qtextcodec.cpp +++ b/qtools/qtextcodec.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Implementation of QTextCodec class ** diff --git a/qtools/qthread.cpp b/qtools/qthread.cpp deleted file mode 100644 index 02c99f2..0000000 --- a/qtools/qthread.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qthread.h" -#include "qthread_p.h" - -QThread::QThread() - : d(new QThreadPrivate) -{ -} - -QThread::~QThread() -{ - QMutexLocker locker(&d->mutex); - if (d->running && !d->finished) - qWarning("QThread: Destroyed while thread is still running"); - delete d; -} - -bool QThread::isFinished() const -{ - QMutexLocker locker(&d->mutex); - return d->finished; -} - -bool QThread::isRunning() const -{ - QMutexLocker locker(&d->mutex); - return d->running; -} - -void QThread::setStackSize(unsigned int stackSize) -{ - QMutexLocker locker(&d->mutex); - if (d->running) - { - qWarning("QThread: Cannot change stack size while thread is running!"); - return; - } - d->stackSize = stackSize; -} - -unsigned int QThread::stackSize() const -{ - QMutexLocker locker(&d->mutex); - return d->stackSize; -} - diff --git a/qtools/qthread.h b/qtools/qthread.h deleted file mode 100644 index 81868bd..0000000 --- a/qtools/qthread.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTHREAD_H -#define QTHREAD_H - -class QThreadPrivate; - -class QThread -{ - public: - explicit QThread(); - virtual ~QThread(); - - bool isFinished() const; - bool isRunning() const; - - void start(); - void terminate(); - void wait(); - void setStackSize(unsigned int stackSize); - unsigned int stackSize() const; - static int idealThreadCount(); - -protected: - // events - virtual void started() {} - virtual void finished() {} - virtual void terminated() {} - - // main loop - virtual void run() {} - -private: - QThreadPrivate *d; - friend class QThreadPrivate; -}; - -#endif // QTHREAD_H diff --git a/qtools/qthread_p.h b/qtools/qthread_p.h deleted file mode 100644 index 87692aa..0000000 --- a/qtools/qthread_p.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTHREAD_P_H -#define QTHREAD_P_H - -#include "qglobal.h" - -#if defined(_OS_UNIX_) || defined(_OS_MAC_) -#include -#elif defined(_OS_WIN32_) -#include -#endif - -#include "qthread.h" -#include "qmutex.h" -#include "qwaitcondition.h" - -class QThreadPrivate -{ -public: - QThreadPrivate(); - ~QThreadPrivate(); - - mutable QMutex mutex; - - bool running; - bool finished; - bool terminated; - uint stackSize; - -#if defined(_OS_UNIX_) || defined(_OS_MAC_) - pthread_t thread_id; - QWaitCondition thread_done; - static void *start(void *arg); - static void finish(void *arg); -#elif defined(_OS_WIN32_) - HANDLE handle; - static unsigned int __stdcall start(void *); - static void finish(void *,bool lockAnyway=TRUE); - int waiters; -#else -#error "unsupported platform!" -#endif -}; - -#endif // QTHREAD_P_H diff --git a/qtools/qthread_unix.cpp b/qtools/qthread_unix.cpp deleted file mode 100644 index 5871605..0000000 --- a/qtools/qthread_unix.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglobal.h" - -#if defined(_OS_HPUX_) -#include -#elif defined(_OS_MAC_) -#undef DEBUG -#include -#elif defined(_OS_BSDI_) -#include -#include -#include -#include -#endif -#include -#include -#include - -#include "qthread.h" -#include "qthread_p.h" - - -/************************************************************************** - ** QThreadPrivate - *************************************************************************/ - -QThreadPrivate::QThreadPrivate() : - running(FALSE), finished(FALSE), terminated(FALSE), stackSize(0) -{ - thread_id = 0; -} - -QThreadPrivate::~QThreadPrivate() -{ -} - -void *QThreadPrivate::start(void *arg) -{ -#ifndef __ANDROID__ - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); -#endif - pthread_cleanup_push(QThreadPrivate::finish, arg); - - QThread *thr = reinterpret_cast(arg); - - thr->started(); -#ifndef __ANDROID__ - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_testcancel(); -#endif - thr->run(); - - pthread_cleanup_pop(1); - return 0; -} - -void QThreadPrivate::finish(void *arg) -{ - QThread *thr = reinterpret_cast(arg); - QThreadPrivate *d = thr->d; - QMutexLocker locker(&d->mutex); - - d->running = FALSE; - d->finished = TRUE; - if (d->terminated) - thr->terminated(); - d->terminated = FALSE; - thr->finished(); - - d->thread_id = 0; - d->thread_done.wakeAll(); -} - - - - -/************************************************************************** - ** QThread - *************************************************************************/ - -void QThread::start() -{ - QMutexLocker locker(&d->mutex); - if (d->running) return; - - // Block the SIGINT signal. The threads will inherit the signal mask. - // This will avoid them catching SIGINT instead of this thread. - sigset_t sigset, oldset; - sigemptyset(&sigset); - sigaddset(&sigset, SIGINT); - pthread_sigmask(SIG_BLOCK, &sigset, &oldset); - - d->running = TRUE; - d->finished = FALSE; - - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); -#ifndef __ANDROID__ - pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); -#endif - if (d->stackSize>0) - { -#if defined(_POSIX_THREAD_ATTR_STACKSIZE) && (_POSIX_THREAD_ATTR_STACKSIZE-0>0) - pthread_attr_setstacksize(&attr,d->stackSize); -#endif - } - int code = pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this); - pthread_attr_destroy(&attr); - - if (code) - { - qWarning("QThread::start: Thread creation error: %d", code); - - d->running = FALSE; - d->finished = FALSE; - d->thread_id = 0; - } - else - { - // Restore the old signal mask only for this thread. - pthread_sigmask(SIG_SETMASK, &oldset, NULL); - } -} - -void QThread::terminate() -{ - QMutexLocker locker(&d->mutex); -#ifndef __ANDROID__ - if (!d->thread_id) return; - - int code = pthread_cancel(d->thread_id); - if (code) - { - qWarning("QThread::start: Thread termination error: %d", code); - } - else - { - d->terminated = TRUE; - } -#endif -} - -void QThread::wait() -{ - QMutexLocker locker(&d->mutex); - if (d->finished || !d->running) return; - - while (d->running) - { - d->thread_done.wait(locker.mutex()); - } -} - -#if defined(QT_LINUXBASE) && !defined(_SC_NPROCESSORS_ONLN) -// LSB doesn't define _SC_NPROCESSORS_ONLN. -# define _SC_NPROCESSORS_ONLN 84 -#endif - -int QThread::idealThreadCount() -{ - int cores = -1; -#if defined(_OS_MAC_) - // Mac OS X - cores = (int)MPProcessorsScheduled(); -#elif defined(_OS_HPUX_) - // HP-UX - struct pst_dynamic psd; - if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1) - { - perror("pstat_getdynamic"); - cores = -1; - } - else - { - cores = (int)psd.psd_proc_cnt; - } -#elif defined(_OS_BSDI_) - // FreeBSD, OpenBSD, NetBSD, BSD/OS - size_t len = sizeof(cores); - int mib[2]; - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - - if (sysctl(mib, 2, &cores, &len, NULL, 0) != 0) - { - perror("sysctl"); - cores = -1; - } -#elif defined(_OS_IRIX_) - // IRIX - cores = (int)sysconf(_SC_NPROC_ONLN); -#else - // the rest: Linux, Solaris, AIX, Tru64 - cores = (int)sysconf(_SC_NPROCESSORS_ONLN); -#endif - return cores; -} - diff --git a/qtools/qthread_win32.cpp b/qtools/qthread_win32.cpp deleted file mode 100644 index 2c62e93..0000000 --- a/qtools/qthread_win32.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qthread.h" -#include "qthread_p.h" - -/************************************************************************** - ** QThreadPrivate - *************************************************************************/ - -QThreadPrivate::QThreadPrivate() : - running(FALSE), finished(FALSE), terminated(FALSE), stackSize(0) -{ - handle = NULL; - waiters = 0; -} - -QThreadPrivate::~QThreadPrivate() -{ -} - -unsigned int __stdcall QThreadPrivate::start(void *arg) -{ - QThread *thr = reinterpret_cast(arg); - thr->started(); - thr->run(); - finish(arg); - return 0; -} - -void QThreadPrivate::finish(void *arg,bool lockAnyway) -{ - QThread *thr = reinterpret_cast(arg); - QThreadPrivate *d = thr->d; - - if (lockAnyway) d->mutex.lock(); - - d->running = FALSE; - d->finished = TRUE; - if (d->terminated) thr->terminated(); - d->terminated = FALSE; - thr->finished(); - - if (!d->waiters) - { - CloseHandle(d->handle); - d->handle = 0; - } - - if (lockAnyway) d->mutex.unlock(); -} - -/************************************************************************** - ** QThread - *************************************************************************/ - -void QThread::start() -{ - QMutexLocker locker(&d->mutex); - - if (d->running) return; - - d->running = TRUE; - d->finished = FALSE; - d->terminated = FALSE; - - d->handle = CreateThread(NULL,d->stackSize, - (LPTHREAD_START_ROUTINE)QThreadPrivate::start,this,0,NULL); - - if (!d->handle) - { - qWarning("QThread::start: Failed to create thread: errno=%d",errno); - d->running = FALSE; - d->finished = TRUE; - return; - } -} - -void QThread::terminate() -{ - QMutexLocker locker(&d->mutex); - if (!d->running) return; - TerminateThread(d->handle, 0); - d->terminated = TRUE; - QThreadPrivate::finish(this); -} - -void QThread::wait() -{ - QMutexLocker locker(&d->mutex); - if (d->finished || !d->running) return; - - ++d->waiters; - locker.mutex()->unlock(); - - WaitForSingleObject(d->handle,INFINITE); - - locker.mutex()->lock(); - --d->waiters; - if (!d->finished) // thread was terminated by someone else - { - d->terminated = TRUE; - QThreadPrivate::finish(this); - } - - if (d->finished && d->waiters) - { - CloseHandle(d->handle); - d->handle = 0; - } -} - -int QThread::idealThreadCount() -{ - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; -} - - diff --git a/qtools/qtools.pro.in b/qtools/qtools.pro.in index ba8a086..21d26cc 100644 --- a/qtools/qtools.pro.in +++ b/qtools/qtools.pro.in @@ -44,12 +44,7 @@ HEADERS = qarray.h \ qvaluestack.h \ qmap.h \ qmodules.h \ - qthread.h \ - qthread_p.h \ - qmutex.h \ - qmutex_p.h \ - qutfcodec.h \ - qwaitcondition.h + qutfcodec.h SOURCES = qbuffer.cpp \ qcollection.cpp \ @@ -74,23 +69,15 @@ SOURCES = qbuffer.cpp \ qstringlist.cpp \ qxml.cpp \ qmap.cpp \ - qthread.cpp \ - qmutex.cpp \ qutfcodec.cpp unix:SOURCES += qfile_unix.cpp \ qdir_unix.cpp \ - qfileinfo_unix.cpp \ - qthread_unix.cpp \ - qmutex_unix.cpp \ - qwaitcondition_unix.cpp + qfileinfo_unix.cpp win32:SOURCES += qfile_win32.cpp \ qdir_win32.cpp \ - qfileinfo_win32.cpp \ - qthread_win32.cpp \ - qmutex_win32.cpp \ - qwaitcondition_win32.cpp + qfileinfo_win32.cpp INCLUDEPATH = . #TMAKE_CXXFLAGS += -DQT_NO_CODECS -DQT_LITE_UNICODE diff --git a/qtools/qwaitcondition.h b/qtools/qwaitcondition.h deleted file mode 100644 index 4d5b3bd..0000000 --- a/qtools/qwaitcondition.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWAITCONDITION_H -#define QWAITCONDITION_H - -#include "qglobal.h" - -class QWaitConditionPrivate; -class QMutex; - -class QWaitCondition -{ -public: - QWaitCondition(); - ~QWaitCondition(); - - void wait(QMutex *mutex); - - void wakeOne(); - void wakeAll(); - -private: - QWaitCondition(const QWaitCondition &); - QWaitCondition &operator=(const QWaitCondition &); - - QWaitConditionPrivate * d; -}; - -#endif // QWAITCONDITION_H diff --git a/qtools/qwaitcondition_unix.cpp b/qtools/qwaitcondition_unix.cpp deleted file mode 100644 index 0a6a09b..0000000 --- a/qtools/qwaitcondition_unix.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwaitcondition.h" -#include "qmutex.h" -#include - -#define MIN(a,b) ((a)<(b)?(a):(b)) - -static void report_error(int code, const char *where, const char *what) -{ - if (code != 0) - qWarning("%s: %s failure: %d", where, what, code); -} - -class QWaitConditionPrivate -{ - public: - pthread_mutex_t mutex; - pthread_cond_t cond; - int waiters; - int wakeups; - - void wait() - { - int code; - for (;;) - { - code = pthread_cond_wait(&cond, &mutex); - if (code == 0 && wakeups == 0) - { - // many vendors warn of spurious wakeups from - // pthread_cond_wait(), especially after signal delivery, - // even though POSIX doesn't allow for it... sigh - continue; - } - break; - } - - --waiters; - if (code == 0) - { - --wakeups; - } - else - { - report_error(code, "QWaitCondition::wait()", "cv wait"); - } - report_error(pthread_mutex_unlock(&mutex), "QWaitCondition::wait()", "mutex unlock"); - } -}; - - -QWaitCondition::QWaitCondition() -{ - d = new QWaitConditionPrivate; - report_error(pthread_mutex_init(&d->mutex, NULL), "QWaitCondition", "mutex init"); - report_error(pthread_cond_init(&d->cond, NULL), "QWaitCondition", "cv init"); - d->waiters = d->wakeups = 0; -} - - -QWaitCondition::~QWaitCondition() -{ - report_error(pthread_cond_destroy(&d->cond), "QWaitCondition", "cv destroy"); - report_error(pthread_mutex_destroy(&d->mutex), "QWaitCondition", "mutex destroy"); - delete d; -} - -void QWaitCondition::wakeOne() -{ - report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeOne()", "mutex lock"); - d->wakeups = MIN(d->wakeups + 1, d->waiters); - report_error(pthread_cond_signal(&d->cond), "QWaitCondition::wakeOne()", "cv signal"); - report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeOne()", "mutex unlock"); -} - -void QWaitCondition::wakeAll() -{ - report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeAll()", "mutex lock"); - d->wakeups = d->waiters; - report_error(pthread_cond_broadcast(&d->cond), "QWaitCondition::wakeAll()", "cv broadcast"); - report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeAll()", "mutex unlock"); -} - -void QWaitCondition::wait(QMutex *mutex) -{ - if (!mutex) return; - - report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wait()", "mutex lock"); - ++d->waiters; - mutex->unlock(); - d->wait(); - mutex->lock(); -} - diff --git a/qtools/qwaitcondition_win32.cpp b/qtools/qwaitcondition_win32.cpp deleted file mode 100644 index 80b7b67..0000000 --- a/qtools/qwaitcondition_win32.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qwaitcondition.h" -#include "qmutex.h" -#include "qinternallist.h" - -//*********************************************************************** -// QWaitConditionPrivate -// ********************************************************************** - -class QWaitConditionEvent -{ -public: - QWaitConditionEvent() : priority(0), wokenUp(false) - { - event = CreateEvent(NULL, TRUE, FALSE, NULL); - } - ~QWaitConditionEvent() { CloseHandle(event); } - int priority; - bool wokenUp; - HANDLE event; -}; - -class EventQueue : public QInternalList -{ - public: - EventQueue() { setAutoDelete(TRUE); } - ~EventQueue() {} -}; - -class QWaitConditionPrivate -{ -public: - QMutex mtx; - EventQueue queue; - EventQueue freeQueue; - - QWaitConditionEvent *pre(); - void wait(QWaitConditionEvent *wce); - void post(QWaitConditionEvent *wce); -}; - -QWaitConditionEvent *QWaitConditionPrivate::pre() -{ - mtx.lock(); - QWaitConditionEvent *wce = - freeQueue.isEmpty() ? new QWaitConditionEvent : freeQueue.take(0); - wce->priority = GetThreadPriority(GetCurrentThread()); - wce->wokenUp = FALSE; - - // insert 'wce' into the queue (sorted by priority) - uint index = 0; - for (; index < queue.count(); ++index) - { - QWaitConditionEvent *current = queue.at(index); - if (current->priority < wce->priority) - break; - } - queue.insert(index, wce); - mtx.unlock(); - - return wce; -} - -void QWaitConditionPrivate::wait(QWaitConditionEvent *wce) -{ - WaitForSingleObject(wce->event, INFINITE); -} - -void QWaitConditionPrivate::post(QWaitConditionEvent *wce) -{ - mtx.lock(); - - // remove 'wce' from the queue - int idx = queue.find(wce); - ASSERT(idx!=-1); - queue.take(idx); - ResetEvent(wce->event); - freeQueue.append(wce); - - // wakeups delivered after the timeout should be forwarded to the next waiter - if (wce->wokenUp && !queue.isEmpty()) - { - QWaitConditionEvent *other = queue.getFirst(); - SetEvent(other->event); - other->wokenUp = TRUE; - } - - mtx.unlock(); -} - -//*********************************************************************** -// QWaitCondition implementation -//*********************************************************************** - -QWaitCondition::QWaitCondition() -{ - d = new QWaitConditionPrivate; -} - -QWaitCondition::~QWaitCondition() -{ - if (!d->queue.isEmpty()) - { - qWarning("QWaitCondition: Destroyed while threads are still waiting"); - } - delete d; -} - -void QWaitCondition::wait(QMutex *mutex) -{ - if (!mutex) return; - - QWaitConditionEvent *wce = d->pre(); - mutex->unlock(); - d->wait(wce); - mutex->lock(); - d->post(wce); -} - -void QWaitCondition::wakeOne() -{ - // wake up the first waiting thread in the queue - QMutexLocker locker(&d->mtx); - for (uint i = 0; i < d->queue.count(); ++i) - { - QWaitConditionEvent *current = d->queue.at(i); - if (current->wokenUp) continue; - SetEvent(current->event); - current->wokenUp = TRUE; - break; - } -} - -void QWaitCondition::wakeAll() -{ - // wake up the all threads in the queue - QMutexLocker locker(&d->mtx); - for (uint i = 0; i < d->queue.count(); ++i) - { - QWaitConditionEvent *current = d->queue.at(i); - SetEvent(current->event); - current->wokenUp = TRUE; - } -} - -- cgit v0.12 From 630774460c480494d7ce66a0f91d49da60403ef4 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 22 Mar 2020 11:50:55 +0100 Subject: Minor tweaks --- src/dotrunner.cpp | 22 +++++++++++----------- src/dotrunner.h | 8 +++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp index db69b30..cb6bd73 100644 --- a/src/dotrunner.cpp +++ b/src/dotrunner.cpp @@ -170,7 +170,7 @@ void DotRunner::addJob(const char *format, const char *output) m_jobs.emplace_back(format, output, args); } -QCString getBaseNameOfOutput(QCString const& output) +QCString getBaseNameOfOutput(const QCString &output) { int index = output.findRev('.'); if (index < 0) return output; @@ -263,10 +263,10 @@ void DotRunnerQueue::enqueue(DotRunner *runner) DotRunner *DotRunnerQueue::dequeue() { std::unique_lock locker(m_mutex); - - // wait until something is added to the queue - m_bufferNotEmpty.wait(locker, [this]() {return !m_queue.empty(); }); - + + // wait until something is added to the queue + m_bufferNotEmpty.wait(locker, [this]() { return !m_queue.empty(); }); + DotRunner *result = m_queue.front(); m_queue.pop(); return result; @@ -292,10 +292,10 @@ void DotWorkerThread::run() { runner->run(); } -} - -void DotWorkerThread::start() -{ - assert(!m_thread); - m_thread = std::make_unique(&DotWorkerThread::run, this); +} + +void DotWorkerThread::start() +{ + assert(!m_thread); + m_thread = std::make_unique(&DotWorkerThread::run, this); } diff --git a/src/dotrunner.h b/src/dotrunner.h index 89eabf8..555ea78 100644 --- a/src/dotrunner.h +++ b/src/dotrunner.h @@ -28,18 +28,16 @@ /** Helper class to run dot from doxygen from multiple threads. */ class DotRunner { - public: struct DotJob { - DotJob(std::string format, - std::string output, - std::string args) - : format(std::move(format)), output(std::move(output)), args(std::move(args)) {} + DotJob(std::string f, std::string o, std::string a) + : format(f), output(o), args(a) {} std::string format; std::string output; std::string args; }; + public: /** Creates a runner for a dot \a file. */ DotRunner(const std::string& absDotName, const std::string& md5Hash = std::string()); -- cgit v0.12