[core] Protecting RCV buffer access #1335
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR protects access to
CRcvBuffer::readMsg(..)
withm_RcvBufferLock
.Together with #1333 fixes #486
In case of the receiver, there are two threads accessing
CUnitQueue
.Both of these threads were protecting access to
CRcvBuffer
and eventually toCUnitQueue
with different mutexes, meaning there was no protection from simultaneous writing viamakeUnit*(..)
functions.The thread that receives packets from the network has the following call stack:
CUDT::processData(CUnit* in_unit)
locks
m_RcvBufferLock
CRcvBuffer::addData(CUnit* unit, int offset)
m_pUnitQueue->makeUnitGood(unit, "addData")
Another thread is the application thread that reads data from the buffer.
Call stack:
CUDT::receiveMessage(..)
locks
m_RecvLock
CRcvBuffer::readMsg(..)
CRcvBuffer::extractData(..)
freeUnitAt(..)
m_pUnitQueue->makeUnitFree(..)