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

Fix GC stop handling #1950

Merged
merged 2 commits into from
Dec 14, 2021
Merged
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
36 changes: 16 additions & 20 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ srt::CUDTUnited::CUDTUnited():
// XXX An unlikely exception thrown from the below calls
// might destroy the application before `main`. This shouldn't
// be a problem in general.
setupMutex(m_GCStopLock, "GCStop");
setupCond(m_GCStopCond, "GCStop");
setupMutex(m_GlobControlLock, "GlobControl");
setupMutex(m_IDLock, "ID");
setupMutex(m_InitLock, "Init");
Expand All @@ -220,6 +222,16 @@ srt::CUDTUnited::~CUDTUnited()
releaseMutex(m_GlobControlLock);
releaseMutex(m_IDLock);
releaseMutex(m_InitLock);
// XXX There's some weird bug here causing this
// to hangup on Windows. This might be either something
// bigger, or some problem in pthread-win32. As this is
// the application cleanup section, this can be temporarily
// tolerated with simply exit the application without cleanup,
// counting on that the system will take care of it anyway.
#ifndef _WIN32
releaseCond(m_GCStopCond);
#endif
releaseMutex(m_GCStopLock);

delete m_pCache;
}
Expand Down Expand Up @@ -258,15 +270,6 @@ int srt::CUDTUnited::startup()

m_bClosing = false;

try
{
setupMutex(m_GCStopLock, "GCStop");
setupCond(m_GCStopCond, "GCStop");
}
catch (...)
{
return -1;
}
if (!StartThread(m_GCThread, garbageCollect, this, "SRT:GC"))
return -1;

Expand Down Expand Up @@ -295,7 +298,10 @@ int srt::CUDTUnited::cleanup()
if (!m_bGCStatus)
return 0;

m_bClosing = true;
{
UniqueLock gclock(m_GCStopLock);
m_bClosing = true;
}
// NOTE: we can do relaxed signaling here because
// waiting on m_GCStopCond has a 1-second timeout,
// after which the m_bClosing flag is cheched, which
Expand All @@ -304,16 +310,6 @@ int srt::CUDTUnited::cleanup()
CSync::signal_relaxed(m_GCStopCond);
m_GCThread.join();

// XXX There's some weird bug here causing this
// to hangup on Windows. This might be either something
// bigger, or some problem in pthread-win32. As this is
// the application cleanup section, this can be temporarily
// tolerated with simply exit the application without cleanup,
// counting on that the system will take care of it anyway.
#ifndef _WIN32
releaseCond(m_GCStopCond);
#endif

m_bGCStatus = false;

// Global destruction code
Expand Down