From 80a4578847dd62f042be5a7496be5d408054294c Mon Sep 17 00:00:00 2001 From: Srivats P Date: Sun, 30 Apr 2023 10:40:49 +0530 Subject: [PATCH] Fix latency timers not getting started/stopped In a previous commit, we start/stop these timers based on number of ports tracking stream stats triggered by RPCs. However, timers cannot be triggered across threads (RPC thread and main thread in this case). This fix uses a queued connection to post it to the other queue. --- server/abstractport.cpp | 12 +++++++----- server/streamtiming.h | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/abstractport.cpp b/server/abstractport.cpp index 56a9530..2fb0b0d 100644 --- a/server/abstractport.cpp +++ b/server/abstractport.cpp @@ -200,11 +200,13 @@ void AbstractPort::addNote(QString note) bool AbstractPort::setTrackStreamStats(bool enable) { - if (enable) - streamTiming_->start(id()); - else - streamTiming_->stop(id()); - + // XXX: This function is called by modify() in context of the RPC + // thread (1 thread per connected client), but the StreamTiming + // singleton resides in the main thread and its' start/stop methods + // start/stop timers which cannot be done across Qt Threads. Hence + // this slightly hacky way of invoking those methods + QMetaObject::invokeMethod(streamTiming_, enable ? "start" : "stop", + Qt::QueuedConnection, Q_ARG(uint, id())); data_.set_is_tracking_stream_stats(enable); return true; diff --git a/server/streamtiming.h b/server/streamtiming.h index d54f690..bd9fb78 100644 --- a/server/streamtiming.h +++ b/server/streamtiming.h @@ -33,10 +33,6 @@ class StreamTiming : public QObject { Q_OBJECT public: - - void start(uint portId); - void stop(uint portId); - bool recordTxTime(uint portId, uint guid, uint ttagId, const struct timespec ×tamp); bool recordRxTime(uint portId, uint guid, uint ttagId, @@ -52,6 +48,10 @@ public: static StreamTiming* instance(); +public slots: + void start(uint portId); + void stop(uint portId); + private: StreamTiming(QObject *parent=nullptr);