ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/XmlTools2/trunk/xmlcustomcode.h
(Generate patch)

Comparing XmlTools2/trunk/xmlcustomcode.h (file contents):
Revision 980 by s10k, Thu Mar 6 16:40:35 2014 UTC vs.
Revision 1056 by s10k, Sat Oct 29 22:52:03 2016 UTC

# Line 9 | Line 9
9   #include <QTextStream>
10   #include <QCoreApplication>
11  
12 + #include <QThreadPool>
13 + #include <QtConcurrent/QtConcurrent>
14 +
15   #define SLOW_SCRIPT_TIME 0.1 // if a user script takes more than 0.1 seconds to execute give a warning.
16 < #define CUSTOM_FILES_PER_THREAD 2
16 > #define CUSTOM_FILES_PER_THREAD 4
17  
18   // Uses a singleton implementation (based on here: http://www.yolinux.com/TUTORIALS/C++Singleton.html)
19   // which allows each thread to keep one script engine without always create/destruct them
# Line 21 | Line 24 | public:
24      void executeCustomCode(const QString &jsString, const QVector<QString> &filesToProcess, const bool backupsEnabled, const bool verboseEnabled);
25   private:
26      static XmlCustomCode* uniqueInstance;
27 +
28      const int numThreads;
29 <    QVector<QScriptEngine*> scriptEngines;
30 <    QVector<QScriptValue*> jsFunctions;
31 <    QVector<QScriptValue*> getXmlDataFunctions;
32 <    QVector<QScriptValue*> setXmlDataFunctions;
29 >    QThreadPool myThreadPool;
30 >    QMutex mutexIsAvailable;
31 >
32 >    struct jsCustomCodeEngine{
33 >        QScriptEngine* scriptEngine;
34 >        QScriptValue* jsFunction;
35 >        QScriptValue* getXmlDataFunction;
36 >        QScriptValue* setXmlDataFunction;
37 >        bool isAvailable;
38 >    };
39 >
40 >    QVector<jsCustomCodeEngine> jsScriptEngines;
41  
42      XmlCustomCode(); // constructor is private (use getInstance)
43      XmlCustomCode(XmlCustomCode const&);             // copy constructor is private
44      XmlCustomCode& operator=(XmlCustomCode const&);  // assignment operator is private
45  
46      void displayJsException(QScriptEngine &engine, QScriptValue &engineResult);
47 +    jsCustomCodeEngine& getAvailableJsEngine();
48  
49      __attribute__((always_inline)) inline void customCodeUnwinding(const QString &fileName, QString &currXmlFileString,
50      QScriptEngine &engine, clock_t &begin, double elapsed_secs, QScriptValue &engineResult, QScriptValue &jsFunction,

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)