Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Fix TSBPD thread create/join protection. #2972

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading