void btDbvtBroadphase::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin, const btVector3& aabbMax) { BroadphaseRayTester callback(rayCallback); btAlignedObjectArray<const btDbvtNode*>* stack = &m_rayTestStacks[0]; #if BT_THREADSAFE // for this function to be threadsafe, each thread must have a separate copy // of this stack. This could be thread-local static to avoid dynamic allocations, // instead of just a local. int threadIndex = btGetCurrentThreadIndex(); btAlignedObjectArray<const btDbvtNode*> localStack; if (threadIndex < m_rayTestStacks.size()) { // use per-thread preallocated stack if possible to avoid dynamic allocations stack = &m_rayTestStacks[threadIndex]; } else { stack = &localStack; } #endif m_sets[0].rayTestInternal(m_sets[0].m_root, rayFrom, rayTo, rayCallback.m_rayDirectionInverse, rayCallback.m_signs, rayCallback.m_lambda_max, aabbMin, aabbMax, *stack, callback); m_sets[1].rayTestInternal(m_sets[1].m_root, rayFrom, rayTo, rayCallback.m_rayDirectionInverse, rayCallback.m_signs, rayCallback.m_lambda_max, aabbMin, aabbMax, *stack, callback); }
unsigned int btQuickprofGetCurrentThreadIndex2() { const unsigned int kNullIndex = ~0U; #if BT_THREADSAFE return btGetCurrentThreadIndex(); #else #if defined(BT_HAVE_TLS) static __thread unsigned int sThreadIndex = kNullIndex; #elif defined(_WIN32) __declspec(thread) static unsigned int sThreadIndex = kNullIndex; #else unsigned int sThreadIndex = 0; return -1; #endif static int gThreadCounter = 0; if (sThreadIndex == kNullIndex) { sThreadIndex = gThreadCounter++; } return sThreadIndex; #endif //BT_THREADSAFE }
bool btIsMainThread() { return btGetCurrentThreadIndex() == 0; }