Fix a possible race condition around MVKMTLBufferAllocation.

I don't think a race is actually possible here, but this makes Thread
Sanitizer happy.
This commit is contained in:
Chip Davis 2019-02-27 15:07:20 -06:00
parent a1be5a37d3
commit d50e654acd
2 changed files with 5 additions and 1 deletions

View File

@ -452,10 +452,11 @@ void MVKCommandEncoder::setComputeBytes(id<MTLComputeCommandEncoder> mtlEncoder,
const MVKMTLBufferAllocation* MVKCommandEncoder::getTempMTLBuffer(NSUInteger length) {
const MVKMTLBufferAllocation* mtlBuffAlloc = getCommandEncodingPool()->acquireMTLBufferAllocation(length);
MVKMTLBufferAllocationPool* pool = mtlBuffAlloc->getPool();
// Return the MTLBuffer allocation to the pool once the command buffer is done with it
[_mtlCmdBuffer addCompletedHandler: ^(id<MTLCommandBuffer> mcb) {
((MVKMTLBufferAllocation*)mtlBuffAlloc)->returnToPool();
pool->returnObjectSafely((MVKMTLBufferAllocation*)mtlBuffAlloc);
}];
return mtlBuffAlloc;

View File

@ -44,6 +44,9 @@ public:
*/
inline void* getContents() const { return (void*)((uintptr_t)_mtlBuffer.contents + _offset); }
/** Returns the pool whence this object was created. */
MVKMTLBufferAllocationPool* getPool() const { return _pool; }
/** Returns this object back to the pool that created it. This will reset the value of _next member. */
void returnToPool();