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)
{
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;

View File

@ -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 &timestamp);
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);