Changeset 1112 for s10k/XmlTools
- Timestamp:
- Sep 8, 2019, 3:21:41 PM (5 years ago)
- Location:
- s10k/XmlTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
s10k/XmlTools/utilglobalvars.h
r1111 r1112 24 24 25 25 static const QString AppName = "XmlTools"; 26 static const QString AppVersion = "2.0 e";26 static const QString AppVersion = "2.0f"; 27 27 #ifdef Q_OS_WIN 28 28 static const QString AppExecutable=AppName+".exe"; -
s10k/XmlTools/xmlcustomcode.cpp
r1073 r1112 37 37 e.getXmlDataFunction = new QScriptValue(e.scriptEngine->evaluate("(function getXmlData() { return $xmlData; })")); 38 38 e.setXmlDataFunction = new QScriptValue(e.scriptEngine->evaluate("(function setXmlData(newXmlData) { $xmlData=newXmlData; })")); 39 e. isAvailable = true;39 e.mutexForEngine = new QMutex; 40 40 41 41 // Add echo function so user can debug the code … … 75 75 if(filesToProcess.size()<=CUSTOM_FILES_PER_THREAD || numThreads == 1){ 76 76 77 jsCustomCodeEngine &jsEngine = getAvailableJsEngine();77 jsCustomCodeEngine &jsEngine = this->jsScriptEngines.first(); 78 78 79 79 // Process all XmlFiles … … 88 88 QVector<QFuture<void>> executingThreads; 89 89 90 for(int i=0 ; i<=filesToProcess.size()-CUSTOM_FILES_PER_THREAD; i+=CUSTOM_FILES_PER_THREAD){90 for(int i=0, iteration = 0; i<=filesToProcess.size()-CUSTOM_FILES_PER_THREAD; i+=CUSTOM_FILES_PER_THREAD, ++iteration){ 91 91 92 executingThreads << 93 QtConcurrent::run(&this->myThreadPool, [=]() 92 executingThreads << QtConcurrent::run(&this->myThreadPool, [=]() 94 93 { 95 mutexIsAvailable.lock(); 96 jsCustomCodeEngine &jsEngine = getAvailableJsEngine(); 97 jsEngine.isAvailable = false; 98 mutexIsAvailable.unlock(); 94 95 const int indexJsEngine = iteration % this->numThreads; 96 97 jsCustomCodeEngine &jsEngine = this->jsScriptEngines[indexJsEngine]; 98 99 jsEngine.mutexForEngine->lock(); 99 100 100 101 QString currXmlFileStringThread; … … 116 117 *jsEngine.jsFunction,*jsEngine.getXmlDataFunction,*jsEngine.setXmlDataFunction,backupsEnabled,verboseEnabled); 117 118 118 mutexIsAvailable.lock(); 119 jsEngine.isAvailable = true; 120 mutexIsAvailable.unlock(); 119 jsEngine.mutexForEngine->unlock(); 121 120 }); 122 121 } … … 131 130 int alreadyProcessedFiles=(filesToProcess.size()/CUSTOM_FILES_PER_THREAD)*CUSTOM_FILES_PER_THREAD; 132 131 133 jsCustomCodeEngine &jsEngine = getAvailableJsEngine();132 jsCustomCodeEngine &jsEngine = this->jsScriptEngines.first(); 134 133 135 134 for(int i=alreadyProcessedFiles; i<filesToProcess.size(); i++){ … … 147 146 } 148 147 } 149 150 XmlCustomCode::jsCustomCodeEngine& XmlCustomCode::getAvailableJsEngine(){151 for(jsCustomCodeEngine &e : this->jsScriptEngines){152 if(e.isAvailable){153 return e;154 }155 }156 157 throw std::runtime_error("Could't find an available js engine for custom command.");158 } -
s10k/XmlTools/xmlcustomcode.h
r1073 r1112 27 27 const int numThreads; 28 28 QThreadPool myThreadPool; 29 QMutex mutexIsAvailable;30 29 31 30 struct jsCustomCodeEngine{ 31 /* No need to delete these... They will stay alive until program quits. */ 32 32 QScriptEngine* scriptEngine; 33 33 QScriptValue* jsFunction; 34 34 QScriptValue* getXmlDataFunction; 35 35 QScriptValue* setXmlDataFunction; 36 bool isAvailable;36 QMutex *mutexForEngine; 37 37 }; 38 38 … … 44 44 45 45 void displayJsException(QScriptEngine &engine, QScriptValue &engineResult); 46 jsCustomCodeEngine& getAvailableJsEngine();47 46 48 47 __attribute__((always_inline)) inline void customCodeUnwinding(const QString &fileName, QString &currXmlFileString, 49 QScriptEngine &engine, clock_t &begin, double elapsed_secs, QScriptValue &engineResult, QScriptValue &jsFunction,50 QScriptValue &getXmlDataFunction, QScriptValue &setXmlDataFunction, const bool &backupsEnabled, const bool &verboseEnabled){48 QScriptEngine &engine, clock_t &begin, double elapsed_secs, QScriptValue &engineResult, QScriptValue &jsFunction, 49 QScriptValue &getXmlDataFunction, QScriptValue &setXmlDataFunction, const bool &backupsEnabled, const bool &verboseEnabled){ 51 50 if(backupsEnabled){ 52 51 UtilXmlTools::backupFile(fileName, verboseEnabled);
Note:
See TracChangeset
for help on using the changeset viewer.