1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-30 08:24:05 +00:00

Wait for buffer to be empty before reallocating memory

This commit is contained in:
Francisco Zurita 2021-05-24 18:34:53 -04:00 committed by Sergey Lipskiy
parent e9d08c33bd
commit 15668b9064

View File

@ -136,8 +136,28 @@ PoolBufferPointer RingBufferPool::createPoolBuffer(const char* _buffer, size_t _
});
// Resize afterwards, we don't want to lose the validity of pointers
// pointing at the old data
// pointing at the old data, also wait until the memory pool is empty,
// we don't want anyone point to the old allocation.
if (m_poolBuffer.size() < realBufferSize) {
const size_t tempInUseStartLocal = m_inUseStartOffset;
const size_t remainingLocal =
tempInUseStartLocal > m_inUseEndOffset || m_full ? static_cast<size_t>(
tempInUseStartLocal - m_inUseEndOffset) :
poolBufferSize - m_inUseEndOffset + tempInUseStartLocal;
if (remainingLocal != realBufferSize) {
m_condition.wait(lock, [this, realBufferSize, poolBufferSize] {
const size_t tempInUseStartLocal = m_inUseStartOffset;
const size_t remainingLocal =
tempInUseStartLocal > m_inUseEndOffset || m_full ? static_cast<size_t>(
tempInUseStartLocal - m_inUseEndOffset) :
poolBufferSize - m_inUseEndOffset + tempInUseStartLocal;
return remainingLocal == realBufferSize;
});
}
m_poolBuffer.resize(realBufferSize);
}
}