| 1204 | } |
| 1205 | |
| 1206 | NATRON_NAMESPACE_ANONYMOUS_ENTER |
| 1207 | |
| 1208 | ///Using QtConcurrent doesn't work with The Foundry Furnace plug-ins because they expect fresh threads |
| 1209 | ///to be created. As QtConcurrent's thread-pool recycles thread, it seems to make Furnace crash. |
| 1210 | ///We think this is because Furnace must keep an internal thread-local state that becomes then dirty |
| 1211 | ///if we re-use the same thread. |
| 1212 | |
| 1213 | static OfxStatus |
| 1214 | threadFunctionWrapper(OfxThreadFunctionV1 func, |
| 1215 | unsigned int threadIndex, |
| 1216 | unsigned int threadMax, |
| 1217 | QThread* spawnerThread, |
| 1218 | void *customArg) |
| 1219 | { |
| 1220 | #ifdef DEBUG |
| 1221 | boost_adaptbx::floating_point::exception_trapping trap(boost_adaptbx::floating_point::exception_trapping::division_by_zero | |
| 1222 | boost_adaptbx::floating_point::exception_trapping::invalid | |
| 1223 | boost_adaptbx::floating_point::exception_trapping::overflow); |
| 1224 | #endif |
| 1225 | assert(threadIndex < threadMax); |
| 1226 | OfxHost::OfxHostDataTLSPtr tls = appPTR->getOFXHost()->getTLSData(); |
| 1227 | tls->threadIndexes.push_back( (int)threadIndex ); |
| 1228 | |
| 1229 | QThread* spawnedThread = QThread::currentThread(); |
| 1230 | if (spawnedThread != spawnerThread) { |
| 1231 | appPTR->getAppTLS()->softCopy(spawnerThread, spawnedThread); |
| 1232 | } |
| 1233 | |
| 1234 | OfxStatus ret = kOfxStatOK; |
| 1235 | try { |
| 1236 | #ifdef DEBUG |
| 1237 | // Uncomment if using plugins that generate FP exceptions |
| 1238 | boost_adaptbx::floating_point::exception_trapping trap(0); |
| 1239 | #endif |
| 1240 | func(threadIndex, threadMax, customArg); |
| 1241 | } catch (const std::bad_alloc & ba) { |
| 1242 | ret = kOfxStatErrMemory; |
| 1243 | } catch (...) { |
| 1244 | ret = kOfxStatFailed; |
| 1245 | } |
| 1246 | |
| 1247 | ///reset back the index otherwise it could mess up the indexes if the same thread is re-used |
| 1248 | tls->threadIndexes.pop_back(); |
| 1249 | |
| 1250 | if (spawnedThread != spawnerThread) { |
| 1251 | appPTR->getAppTLS()->cleanupTLSForThread(); |
| 1252 | } |
| 1253 | |
| 1254 | return ret; |
| 1255 | } |
| 1256 | |
| 1257 | class OfxThread |
| 1258 | : public QThread |
no test coverage detected