Skip to content

Commit 54c002f

Browse files
[core] Fix TSBPD thread create/join protection.
Co-authored-by: Sektor van Skijlen <[email protected]>
1 parent 0680092 commit 54c002f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

srtcore/core.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9992,12 +9992,13 @@ bool srt::CUDT::overrideSndSeqNo(int32_t seq)
99929992
int srt::CUDT::checkLazySpawnTsbPdThread()
99939993
{
99949994
const bool need_tsbpd = m_bTsbPd || m_bGroupTsbPd;
9995+
if (!need_tsbpd)
9996+
return 0;
99959997

9996-
if (need_tsbpd && !m_RcvTsbPdThread.joinable())
9998+
ScopedLock lock(m_RcvTsbPdStartupLock);
9999+
if (!m_RcvTsbPdThread.joinable())
999710000
{
9998-
ScopedLock lock(m_RcvTsbPdStartupLock);
9999-
10000-
if (m_bClosing) // Check again to protect join() in CUDT::releaseSync()
10001+
if (m_bClosing) // Check m_bClosing to protect join() in CUDT::releaseSync().
1000110002
return -1;
1000210003

1000310004
HLOGP(qrlog.Debug, "Spawning Socket TSBPD thread");

srtcore/core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ class CUDT
995995
sync::CThread m_RcvTsbPdThread; // Rcv TsbPD Thread handle
996996
sync::Condition m_RcvTsbPdCond; // TSBPD signals if reading is ready. Use together with m_RecvLock
997997
bool m_bTsbPdNeedsWakeup; // Signal TsbPd thread to wake up on RCV buffer state change.
998-
sync::Mutex m_RcvTsbPdStartupLock; // Protects TSBPD thread creating and joining
998+
sync::Mutex m_RcvTsbPdStartupLock; // Protects TSBPD thread creation and joining.
999999

10001000
CallbackHolder<srt_listen_callback_fn> m_cbAcceptHook;
10011001
CallbackHolder<srt_connect_callback_fn> m_cbConnectHook;

0 commit comments

Comments
 (0)