Change StreamTiming::timing_ from QList to QHash

Using QList meant we need to know the port count in the constructor - which is
difficult to know because StreamTiming is designed as a singleton
This commit is contained in:
Srivats P 2023-03-29 17:13:12 +05:30
parent 39c8d6f5f3
commit fc2d8408fa
2 changed files with 4 additions and 7 deletions

View File

@ -21,12 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "timestamp.h"
StreamTiming::StreamTiming(int portCount)
StreamTiming::StreamTiming()
: QObject(nullptr) // FIXME: parent
{
for (int i = 0; i < portCount; i++)
timing_.append(new QHash<Key, Timing>);
timer_ = new QTimer(this);
connect(timer_, &QTimer::timeout, this, &StreamTiming::processRecords);
timer_->setInterval(3000);
@ -152,7 +149,7 @@ StreamTiming* StreamTiming::instance()
static StreamTiming *instance{nullptr};
if (!instance)
instance = new StreamTiming(10); // FIXME: WRONG param
instance = new StreamTiming();
return instance;
}

View File

@ -30,7 +30,7 @@ class StreamTiming : public QObject
{
Q_OBJECT
public:
StreamTiming(int portCount);
StreamTiming();
bool recordTxTime(uint portId, uint guid, uint ttagId,
struct timespec timestamp);
@ -73,7 +73,7 @@ private:
typedef quint32 Key;
QHash<Key, TtagData> txHash_;
QHash<Key, TtagData> rxHash_;
QList<QHash<Key, Timing>*> timing_; // list index => portId
QHash<uint, QHash<Key, Timing>*> timing_; // outer key => portId
QMutex txHashLock_;
QMutex rxHashLock_;
QMutex timingLock_; // FIXME: change to RW lock?