Skip to content

Commit

Permalink
[core] Fix TSBPD thread create/join protection.
Browse files Browse the repository at this point in the history
Co-authored-by: Sektor van Skijlen <[email protected]>
  • Loading branch information
maxsharabayko and ethouris committed Jul 9, 2024
1 parent 0680092 commit 54c002f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9992,12 +9992,13 @@ bool srt::CUDT::overrideSndSeqNo(int32_t seq)
int srt::CUDT::checkLazySpawnTsbPdThread()
{
const bool need_tsbpd = m_bTsbPd || m_bGroupTsbPd;
if (!need_tsbpd)
return 0;

if (need_tsbpd && !m_RcvTsbPdThread.joinable())
ScopedLock lock(m_RcvTsbPdStartupLock);
if (!m_RcvTsbPdThread.joinable())
{
ScopedLock lock(m_RcvTsbPdStartupLock);

if (m_bClosing) // Check again to protect join() in CUDT::releaseSync()
if (m_bClosing) // Check m_bClosing to protect join() in CUDT::releaseSync().
return -1;

HLOGP(qrlog.Debug, "Spawning Socket TSBPD thread");
Expand Down
2 changes: 1 addition & 1 deletion srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ class CUDT
sync::CThread m_RcvTsbPdThread; // Rcv TsbPD Thread handle
sync::Condition m_RcvTsbPdCond; // TSBPD signals if reading is ready. Use together with m_RecvLock
bool m_bTsbPdNeedsWakeup; // Signal TsbPd thread to wake up on RCV buffer state change.
sync::Mutex m_RcvTsbPdStartupLock; // Protects TSBPD thread creating and joining
sync::Mutex m_RcvTsbPdStartupLock; // Protects TSBPD thread creation and joining.

CallbackHolder<srt_listen_callback_fn> m_cbAcceptHook;
CallbackHolder<srt_connect_callback_fn> m_cbConnectHook;
Expand Down

0 comments on commit 54c002f

Please sign in to comment.