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.
This commit is contained in:
Srivats P 2023-04-30 10:40:49 +05:30
parent 649fa03575
commit 4ba98cc520
2 changed files with 11 additions and 9 deletions

View File

@ -200,11 +200,13 @@ void AbstractPort::addNote(QString note)
bool AbstractPort::setTrackStreamStats(bool enable) bool AbstractPort::setTrackStreamStats(bool enable)
{ {
if (enable) // XXX: This function is called by modify() in context of the RPC
streamTiming_->start(id()); // thread (1 thread per connected client), but the StreamTiming
else // singleton resides in the main thread and its' start/stop methods
streamTiming_->stop(id()); // 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); data_.set_is_tracking_stream_stats(enable);
return true; return true;

View File

@ -33,10 +33,6 @@ class StreamTiming : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
void start(uint portId);
void stop(uint portId);
bool recordTxTime(uint portId, uint guid, uint ttagId, bool recordTxTime(uint portId, uint guid, uint ttagId,
const struct timespec &timestamp); const struct timespec &timestamp);
bool recordRxTime(uint portId, uint guid, uint ttagId, bool recordRxTime(uint portId, uint guid, uint ttagId,
@ -52,6 +48,10 @@ public:
static StreamTiming* instance(); static StreamTiming* instance();
public slots:
void start(uint portId);
void stop(uint portId);
private: private:
StreamTiming(QObject *parent=nullptr); StreamTiming(QObject *parent=nullptr);