Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __THREADEDLOOPMACROS_HPP__
00042 #define __THREADEDLOOPMACROS_HPP__
00043
00044 #include <QtGlobal>
00045
00046 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
00047 #include <QtConcurrent>
00048 #endif
00049
00050 #include <QtConcurrentRun>
00051 #include <QFutureSynchronizer>
00052
00053 #include <openfluid/base/LoopMacros.hpp>
00054
00055
00056
00057
00058
00059
00060 #define _THREADSYNCID(_id) _M_##_id##_Sync
00061
00062
00063 #define _APPLY_UNITS_ORDERED_LOOP_THREADED_WITHID(id,unitclass,funcptr,...) \
00064 openfluid::core::UnitsList_t* _UNITSLISTID(id) = mp_CoreData->getUnits(unitclass)->getList(); \
00065 if (_UNITSLISTID(id) != NULL) \
00066 { \
00067 openfluid::core::UnitsList_t::iterator _UNITSLISTITERID(id) = _UNITSLISTID(id)->begin(); \
00068 if (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end()) \
00069 { \
00070 openfluid::core::PcsOrd_t _PCSORDID(id) = _UNITSLISTITERID(id)->getProcessOrder(); \
00071 while (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end()) \
00072 { \
00073 QFutureSynchronizer<void> _THREADSYNCID(id); \
00074 while (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end() && _UNITSLISTITERID(id)->getProcessOrder() == _PCSORDID(id)) \
00075 { \
00076 try \
00077 { \
00078 _THREADSYNCID(id).addFuture(QtConcurrent::run(boost::bind(&funcptr,this,&(*_UNITSLISTITERID(id)),## __VA_ARGS__)));\
00079 if (_THREADSYNCID(id).futures().size() == OPENFLUID_GetSimulatorMaxThreads())\
00080 { \
00081 _THREADSYNCID(id).waitForFinished(); \
00082 _THREADSYNCID(id).clearFutures(); \
00083 }\
00084 }\
00085 catch(QtConcurrent::UnhandledException& E) \
00086 { \
00087 throw openfluid::base::FrameworkException("Unknown exception thrown from compute thread"); \
00088 } \
00089 ++_UNITSLISTITERID(id); \
00090 } \
00091 _THREADSYNCID(id).waitForFinished(); \
00092 _THREADSYNCID(id).clearFutures(); \
00093 if (_UNITSLISTITERID(id) != _UNITSLISTID(id)->end()) _PCSORDID(id) = _UNITSLISTITERID(id)->getProcessOrder(); \
00094 } \
00095 } \
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 #define APPLY_UNITS_ORDERED_LOOP_THREADED(unitclass,funcptr,...) \
00105 _APPLY_UNITS_ORDERED_LOOP_THREADED_WITHID(__LINE__,unitclass,funcptr,## __VA_ARGS__)
00106
00107
00108
00109 #define _APPLY_ALLUNITS_ORDERED_LOOP_THREADED_WITHID(id,funcptr,...) \
00110 openfluid::core::UnitsPtrList_t* _UNITSPTRLISTID(id) = mp_CoreData->getUnitsGlobally(); \
00111 if (_UNITSPTRLISTID(id) != NULL) \
00112 { \
00113 openfluid::core::UnitsPtrList_t::iterator _UNITSPTRLISTITERID(id) = _UNITSPTRLISTID(id)->begin(); \
00114 if (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end()) \
00115 { \
00116 openfluid::core::PcsOrd_t _PCSORDID(id) = (*_UNITSPTRLISTITERID(id))->getProcessOrder(); \
00117 while (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end()) \
00118 { \
00119 QFutureSynchronizer<void> _THREADSYNCID(id); \
00120 while (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end() && (*_UNITSPTRLISTITERID(id))->getProcessOrder() == _PCSORDID(id)) \
00121 { \
00122 try \
00123 { \
00124 _THREADSYNCID(id).addFuture(QtConcurrent::run(boost::bind(&funcptr,this,(*_UNITSPTRLISTITERID(id)),## __VA_ARGS__)));\
00125 if (_THREADSYNCID(id).futures().size() == OPENFLUID_GetSimulatorMaxThreads())\
00126 { \
00127 _THREADSYNCID(id).waitForFinished(); \
00128 _THREADSYNCID(id).clearFutures(); \
00129 }\
00130 }\
00131 catch(QtConcurrent::UnhandledException& E) \
00132 { \
00133 throw openfluid::base::FrameworkException("Unknown exception thrown from compute thread"); \
00134 } \
00135 ++_UNITSPTRLISTITERID(id); \
00136 } \
00137 _THREADSYNCID(id).waitForFinished(); \
00138 _THREADSYNCID(id).clearFutures(); \
00139 if (_UNITSPTRLISTITERID(id) != _UNITSPTRLISTID(id)->end()) _PCSORDID(id) = (*_UNITSPTRLISTITERID(id))->getProcessOrder(); \
00140 } \
00141 } \
00142 }
00143
00144
00145
00146
00147
00148
00149 #define APPLY_ALLUNITS_ORDERED_LOOP_THREADED(funcptr,...) \
00150 _APPLY_ALLUNITS_ORDERED_LOOP_THREADED_WITHID(__LINE__,funcptr,## __VA_ARGS__)
00151
00152
00153
00154
00155
00156
00157
00158
00159 #endif