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

Stop tree updates before tree class deconstruction #1363

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ bool AdaptiveStream::ensureSegment()
{
// wait until worker is ready for new segment
std::unique_lock<std::mutex> lck(thread_data_->mutex_dl_);

if (state_ == STOPPED)
return false;

// lock live segment updates
std::lock_guard<adaptive::AdaptiveTree::TreeUpdateThread> lckUpdTree(tree_.GetTreeUpdMutex());

Expand Down
11 changes: 11 additions & 0 deletions src/common/AdaptiveTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,24 @@ namespace adaptive
// If paused, wait until last "Resume" will be called
std::unique_lock<std::mutex> lckWait(m_waitMutex);
m_cvWait.wait(lckWait, [&] { return m_waitQueue == 0; });
if (m_threadStop)
break;

updLck.lock();
m_tree->RefreshLiveSegments();
}
}
}

void AdaptiveTree::TreeUpdateThread::Stop()
{
m_threadStop = true;
// If an update is already in progress wait until exit
std::lock_guard<std::mutex> updLck{m_updMutex};
m_cvUpdInterval.notify_all();
m_cvWait.notify_all();
}

void AdaptiveTree::TreeUpdateThread::Pause()
{
// If an update is already in progress the wait until its finished
Expand Down
5 changes: 5 additions & 0 deletions src/common/AdaptiveTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ class ATTR_DLL_LOCAL AdaptiveTree
AdaptiveTree(const AdaptiveTree& left);
virtual ~AdaptiveTree()
{
m_updThread.Stop();

for (auto period : periods_)
delete period;
}
Expand Down Expand Up @@ -639,6 +641,9 @@ class ATTR_DLL_LOCAL AdaptiveTree
// \brief As "std::mutex" unlock, but resume the manifest updates (support std::lock_guard).
void unlock() { Resume(); }

// \brief Stop performing new updates.
void Stop();

private:
void Worker();
void Pause();
Expand Down
Loading