MCPcopy Create free account
hub / github.com/MrKepzie/Natron / threadFunctionWrapper

Function threadFunctionWrapper

Engine/OfxHost.cpp:1195–1235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1193}
1194
1195NATRON_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
1202static OfxStatus
1203threadFunctionWrapper(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
1237class OfxThread
1238 : public QThread

Callers

nothing calls this directly

Calls 7

getOFXHostMethod · 0.80
softCopyMethod · 0.80
getAppTLSMethod · 0.80
pop_backMethod · 0.80
cleanupTLSForThreadMethod · 0.80
getTLSDataMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected