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

Method startWrite

physx/source/physx/src/NpScene.cpp:2565–2609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2563#if NP_ENABLE_THREAD_CHECKS
2564
2565NpScene::StartWriteResult::Enum NpScene::startWrite(bool allowReentry)
2566{
2567 PX_COMPILE_TIME_ASSERT(sizeof(ThreadReadWriteCount) == 4);
2568
2569 if (mScene.getFlags() & PxSceneFlag::eREQUIRE_RW_LOCK)
2570 {
2571 ThreadReadWriteCount localCounts(TlsGetValue(mThreadReadWriteDepth));
2572
2573 if (mBetweenFetchResults)
2574 return StartWriteResult::eIN_FETCHRESULTS;
2575
2576 // ensure we already have the write lock
2577 return localCounts.writeLockDepth > 0 ? StartWriteResult::eOK : StartWriteResult::eNO_LOCK;
2578 }
2579
2580 {
2581 ThreadReadWriteCount localCounts(TlsGetValue(mThreadReadWriteDepth));
2582 StartWriteResult::Enum result;
2583
2584 if (mBetweenFetchResults)
2585 result = StartWriteResult::eIN_FETCHRESULTS;
2586
2587 // check we are the only thread reading (allows read->write order on a single thread) and no other threads are writing
2588 else if (mConcurrentReadCount != localCounts.readDepth || mConcurrentWriteCount != localCounts.writeDepth)
2589 result = StartWriteResult::eRACE_DETECTED;
2590
2591 else
2592 result = StartWriteResult::eOK;
2593
2594 // increment shared write counter
2595 Ps::atomicIncrement(&mConcurrentWriteCount);
2596
2597 // in the normal case (re-entry is allowed) then we simply increment
2598 // the writeDepth by 1, otherwise (re-entry is not allowed) increment
2599 // by 2 to force subsequent writes to fail by creating a mismatch between
2600 // the concurrent write counter and the local counter, any value > 1 will do
2601 localCounts.writeDepth += allowReentry ? 1 : 2;
2602 TlsSetValue(mThreadReadWriteDepth, localCounts.getData());
2603
2604 if (result != StartWriteResult::eOK)
2605 Ps::atomicIncrement(&mConcurrentErrorCount);
2606
2607 return result;
2608 }
2609}
2610
2611void NpScene::stopWrite(bool allowReentry)
2612{

Callers 1

NpWriteCheckMethod · 0.80

Calls 5

TlsGetValueFunction · 0.50
atomicIncrementFunction · 0.50
TlsSetValueFunction · 0.50
getFlagsMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected