Skip to content

Commit

Permalink
[core] Added missing lock to CSndBuffer::readData
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Jan 24, 2022
1 parent 5773901 commit 308cd30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ int CSndBuffer::readData(CPacket& w_packet, steady_clock::time_point& w_srctime,
int readlen = 0;
w_seqnoinc = 0;

ScopedLock bufferguard(m_BufLock);
while (m_pCurrBlock != m_pLastBlock)
{
// Make the packet REFLECT the data stored in the buffer.
Expand Down
7 changes: 7 additions & 0 deletions srtcore/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ class CSndBuffer
/// @param [in] data pointer to the user data block.
/// @param [in] len size of the block.
/// @param [inout] w_mctrl Message control data
SRT_ATTR_EXCLUDES(m_BufLock)
void addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl);

/// Read a block of data from file and insert it into the sending list.
/// @param [in] ifs input file stream.
/// @param [in] len size of the block.
/// @return actual size of data added from the file.
SRT_ATTR_EXCLUDES(m_BufLock)
int addBufferFromFile(std::fstream& ifs, int len);

/// Find data position to pack a DATA packet from the furthest reading point.
Expand All @@ -147,6 +149,7 @@ class CSndBuffer
/// @param [in] kflags Odd|Even crypto key flag
/// @param [out] seqnoinc the number of packets skipped due to TTL, so that seqno should be incremented.
/// @return Actual length of data read.
SRT_ATTR_EXCLUDES(m_BufLock)
int readData(CPacket& w_packet, time_point& w_origintime, int kflgs, int& w_seqnoinc);

/// Find data position to pack a DATA packet for a retransmission.
Expand All @@ -155,12 +158,14 @@ class CSndBuffer
/// @param [out] origintime origin time stamp of the message
/// @param [out] msglen length of the message
/// @return Actual length of data read (return 0 if offset too large, -1 if TTL exceeded).
SRT_ATTR_EXCLUDES(m_BufLock)
int readData(const int offset, CPacket& w_packet, time_point& w_origintime, int& w_msglen);

/// Get the time of the last retransmission (if any) of the DATA packet.
/// @param [in] offset offset from the last ACK point (backward sequence number difference)
///
/// @return Last time of the last retransmission event for the corresponding DATA packet.
SRT_ATTR_EXCLUDES(m_BufLock)
time_point getPacketRexmitTime(const int offset);

/// Update the ACK point and may release/unmap/return the user data according to the flag.
Expand All @@ -173,6 +178,7 @@ class CSndBuffer
/// @return Current size of the data in the sending list.
int getCurrBufSize() const;

SRT_ATTR_EXCLUDES(m_BufLock)
int dropLateData(int& bytes, int32_t& w_first_msgno, const time_point& too_late_time);

void updAvgBufSize(const time_point& time);
Expand All @@ -181,6 +187,7 @@ class CSndBuffer

/// @brief Get the buffering delay of the oldest message in the buffer.
/// @return the delay value.
SRT_ATTR_EXCLUDES(m_BufLock)
duration getBufferingDelay(const time_point& tnow) const;

uint64_t getInRatePeriod() const { return m_InRatePeriod; }
Expand Down

0 comments on commit 308cd30

Please sign in to comment.