| 1193 | } |
| 1194 | |
| 1195 | NATRON_NAMESPACE_ANONYMOUS_ENTER |
| 1196 | |
| 1197 | ///Using QtConcurrent doesn't work with The Foundry Furnace plug-ins because they expect fresh threads |
| 1198 | ///to be created. As QtConcurrent's thread-pool recycles thread, it seems to make Furnace crash. |
| 1199 | ///We think this is because Furnace must keep an internal thread-local state that becomes then dirty |
| 1200 | ///if we re-use the same thread. |
| 1201 | |
| 1202 | static OfxStatus |
| 1203 | threadFunctionWrapper(OfxThreadFunctionV1 func, |
| 1204 | unsigned int threadIndex, |
| 1205 | unsigned int threadMax, |
| 1206 | QThread* spawnerThread, |
| 1207 | void *customArg) |
| 1208 | { |
| 1209 | assert(threadIndex < threadMax); |
| 1210 | OfxHost::OfxHostDataTLSPtr tls = appPTR->getOFXHost()->getTLSData(); |
| 1211 | tls->threadIndexes.push_back( (int)threadIndex ); |
| 1212 | |
| 1213 | QThread* spawnedThread = QThread::currentThread(); |
| 1214 | if (spawnedThread != spawnerThread) { |
| 1215 | appPTR->getAppTLS()->softCopy(spawnerThread, spawnedThread); |
| 1216 | } |
| 1217 | |
| 1218 | OfxStatus ret = kOfxStatOK; |
| 1219 | try { |
| 1220 | func(threadIndex, threadMax, customArg); |
| 1221 | } catch (const std::bad_alloc & ba) { |
| 1222 | ret = kOfxStatErrMemory; |
| 1223 | } catch (...) { |
| 1224 | ret = kOfxStatFailed; |
| 1225 | } |
| 1226 | |
| 1227 | ///reset back the index otherwise it could mess up the indexes if the same thread is re-used |
| 1228 | tls->threadIndexes.pop_back(); |
| 1229 | |
| 1230 | if (spawnedThread != spawnerThread) { |
| 1231 | appPTR->getAppTLS()->cleanupTLSForThread(); |
| 1232 | } |
| 1233 | |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | class OfxThread |
| 1238 | : public QThread |
nothing calls this directly
no test coverage detected