| 2613 | #if NP_ENABLE_THREAD_CHECKS |
| 2614 | |
| 2615 | NpScene::StartWriteResult::Enum NpScene::startWrite(bool allowReentry) |
| 2616 | { |
| 2617 | PX_COMPILE_TIME_ASSERT(sizeof(ThreadReadWriteCount) == 4); |
| 2618 | |
| 2619 | if (mScene.getFlags() & PxSceneFlag::eREQUIRE_RW_LOCK) |
| 2620 | { |
| 2621 | ThreadReadWriteCount localCounts(TlsGetValue(mThreadReadWriteDepth)); |
| 2622 | |
| 2623 | if (mBetweenFetchResults) |
| 2624 | return StartWriteResult::eIN_FETCHRESULTS; |
| 2625 | |
| 2626 | // ensure we already have the write lock |
| 2627 | return localCounts.writeLockDepth > 0 ? StartWriteResult::eOK : StartWriteResult::eNO_LOCK; |
| 2628 | } |
| 2629 | |
| 2630 | { |
| 2631 | ThreadReadWriteCount localCounts(TlsGetValue(mThreadReadWriteDepth)); |
| 2632 | StartWriteResult::Enum result; |
| 2633 | |
| 2634 | if (mBetweenFetchResults) |
| 2635 | result = StartWriteResult::eIN_FETCHRESULTS; |
| 2636 | |
| 2637 | // check we are the only thread reading (allows read->write order on a single thread) and no other threads are writing |
| 2638 | else if (mConcurrentReadCount != localCounts.readDepth || mConcurrentWriteCount != localCounts.writeDepth) |
| 2639 | result = StartWriteResult::eRACE_DETECTED; |
| 2640 | |
| 2641 | else |
| 2642 | result = StartWriteResult::eOK; |
| 2643 | |
| 2644 | // increment shared write counter |
| 2645 | Ps::atomicIncrement(&mConcurrentWriteCount); |
| 2646 | |
| 2647 | // in the normal case (re-entry is allowed) then we simply increment |
| 2648 | // the writeDepth by 1, otherwise (re-entry is not allowed) increment |
| 2649 | // by 2 to force subsequent writes to fail by creating a mismatch between |
| 2650 | // the concurrent write counter and the local counter, any value > 1 will do |
| 2651 | localCounts.writeDepth += allowReentry ? 1 : 2; |
| 2652 | TlsSetValue(mThreadReadWriteDepth, localCounts.getData()); |
| 2653 | |
| 2654 | if (result != StartWriteResult::eOK) |
| 2655 | Ps::atomicIncrement(&mConcurrentErrorCount); |
| 2656 | |
| 2657 | return result; |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | void NpScene::stopWrite(bool allowReentry) |
| 2662 | { |
no test coverage detected