Howto: unique parsejob

Niko Sams niko.sams at gmail.com
Sat Feb 7 20:38:24 UTC 2009


On Sat, Feb 7, 2009 at 7:27 PM, Niko Sams <niko.sams at gmail.com> wrote:
> On Sat, Feb 7, 2009 at 5:48 PM, Milian Wolff <mail at milianw.de> wrote:
>> Hi devs!
>>
>> Again I got a problem I'm not able to solve: How do I make parsejobs unique?
>> My case:
>>
>> clean kdevduchain
>> start kdevelop and reopen last documents (3 PHP files)
>> each one of these tries to get the internalfunctions which does not exist and
>> thus creates a parsejob for it and run it. That way it can be sure it's
>> finished and can continue with parsing the real document.
> we could create a mutex that lets the other threads wait for the first
> one to finish.
You can test the attached patch - that should fix the problem

Niko
-------------- next part --------------
Index: phpparsejob.cpp
===================================================================
--- phpparsejob.cpp	(Revision 922573)
+++ phpparsejob.cpp	(Arbeitskopie)
@@ -66,6 +66,9 @@
 {
 }
 
+QMutex ParseJob::m_internalFunctionsMutex;
+
+
 ParseJob::~ParseJob()
 {
 }
@@ -88,17 +91,20 @@
 
 void ParseJob::run()
 {
-    for (uint i=0; i < internalFunctionFilesCount; i++) {
-        if (document() == internalFunctionFiles[i]) break;
-        TopDUContext *top = 0;
-        {
-            DUChainReadLocker lock(DUChain::lock());
-            top = DUChain::self()->chainForDocument(internalFunctionFiles[i]);
+    if (document() != IndexedString("internalfunctions")) {
+        QMutexLocker lock(&m_internalFunctionsMutex);
+        for (uint i=0; i < internalFunctionFilesCount; i++) {
+            if (document() == internalFunctionFiles[i]) break;
+            TopDUContext *top = 0;
+            {
+                DUChainReadLocker lock(DUChain::lock());
+                top = DUChain::self()->chainForDocument(internalFunctionFiles[i]);
+            }
+            if (!top) {
+                ParseJob job(KUrl(internalFunctionFiles[i].str()));
+                job.run();
+            }
         }
-        if (!top) {
-            ParseJob job(KUrl(internalFunctionFiles[i].str()));
-            job.run();
-        }
     }
 
     {
Index: phpparsejob.h
===================================================================
--- phpparsejob.h	(Revision 922573)
+++ phpparsejob.h	(Arbeitskopie)
@@ -76,6 +76,7 @@
     KUrl m_url;
     KTextEditor::Range m_textRangeToParse;
     ParseJob *m_parentJob; ///< parent job if this one is an include
+    static QMutex m_internalFunctionsMutex;
 
     /**
      * Checks if a parent job parses already \p document. Used to prevent


More information about the KDevelop-devel mailing list