MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / start

Method start

physx/source/foundation/src/unix/PsUnixThread.cpp:189–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189void ThreadImpl::start(uint32_t stackSize, Runnable* runnable)
190{
191 if(getThread(this)->state != _PxThreadNotStarted)
192 return;
193
194 if(stackSize == 0)
195 stackSize = getDefaultStackSize();
196
197#if defined(PTHREAD_STACK_MIN) && !defined(ANDROID)
198 if(stackSize < PTHREAD_STACK_MIN)
199 {
200 shdfnd::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__,
201 "ThreadImpl::start(): stack size was set below PTHREAD_STACK_MIN");
202 stackSize = PTHREAD_STACK_MIN;
203 }
204#endif
205
206 if(runnable && !getThread(this)->arg && !getThread(this)->fn)
207 getThread(this)->arg = runnable;
208
209 pthread_attr_t attr;
210 int status = pthread_attr_init(&attr);
211 PX_ASSERT(!status);
212 PX_UNUSED(status);
213
214 status = pthread_attr_setstacksize(&attr, stackSize);
215 PX_ASSERT(!status);
216#if PX_PS4
217 status = pthreadCreatePS4(&getThread(this)->thread, &attr, PxThreadStart, this, getThread(this)->name);
218#else
219 status = pthread_create(&getThread(this)->thread, &attr, PxThreadStart, this);
220#endif
221 PX_ASSERT(!status);
222
223 // wait for thread to startup and write out TID
224 // otherwise TID dependent calls like setAffinity will fail.
225 while(atomicCompareExchange(&(getThread(this)->threadStarted), 1, 1) == 0)
226 yield();
227
228 // here we are sure that getThread(this)->state >= _PxThreadStarted
229
230 status = pthread_attr_destroy(&attr);
231 PX_ASSERT(!status);
232
233 // apply stored affinity mask
234 if(getThread(this)->affinityMask)
235 setAffinityMask(getThread(this)->affinityMask);
236
237#if !PX_PS4
238 if (getThread(this)->name)
239 setName(getThread(this)->name);
240#endif
241}
242
243void ThreadImpl::signalQuit()
244{

Callers 4

threadCreateFunction · 0.45
BackgroundLoaderMethod · 0.45
mainInitializeFunction · 0.45
DefaultCpuDispatcherMethod · 0.45

Calls 4

PX_UNUSEDFunction · 0.85
errorMethod · 0.80
getThreadFunction · 0.70
atomicCompareExchangeFunction · 0.70

Tested by

no test coverage detected