Skip to content

Commit

Permalink
Graceful termination of the updater thread (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
xurei authored Oct 27, 2024
1 parent c196ba7 commit 40d9089
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions source-profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ PerfTreeModel::PerfTreeModel(QObject *parent) : QAbstractItemModel(parent)

obs_frontend_add_event_callback(frontend_event, this);

updaterRunning = true;
updater.reset(new QuickThread([this] {
while (true) {
while (updaterRunning) {
obs_queue_task(
OBS_TASK_UI, [](void *) {}, nullptr, true);
QThread::msleep(refreshInterval);
updateData();
}
}));

updater->start();
}

Expand Down Expand Up @@ -664,8 +664,13 @@ bool PerfViewerProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so

PerfTreeModel::~PerfTreeModel()
{
if (updater)
updater->terminate();
if (updater) {
updaterRunning = false;
if (!updater->wait(1000)) {
blog(LOG_WARNING, "[source-profiler] Updater hanged for 1s. Forced terminate");
updater->terminate();
}
}

obs_frontend_remove_event_callback(frontend_event, this);

Expand Down
1 change: 1 addition & 0 deletions source-profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private slots:
PerfTreeItem *rootItem = nullptr;
QList<PerfTreeColumn> columns;
std::unique_ptr<QThread> updater;
bool updaterRunning;

enum ShowMode showMode = ShowMode::SCENE;
bool activeOnly = true;
Expand Down

0 comments on commit 40d9089

Please sign in to comment.