thread safe timing of domain connection

This commit is contained in:
Stephen Birarda 2015-05-26 16:49:18 -07:00
parent 08affbfd0d
commit 9cb6ccaa46
3 changed files with 14 additions and 5 deletions

View file

@ -69,11 +69,12 @@ DomainConnectionDialog::DomainConnectionDialog(QWidget* parent) :
}
}
// setup a horizontal box layout
QHBoxLayout* hBoxLayout = new QHBoxLayout;
hBoxLayout->addWidget(timeTable);
hBoxLayout->setSizeConstraint(QLayout::SetMinimumSize);
timeTable->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// resize the table columns
timeTable->resizeColumnsToContents();
// figure out the size of the table so we can size the dialog
@ -87,6 +88,7 @@ DomainConnectionDialog::DomainConnectionDialog(QWidget* parent) :
tableHeight += timeTable->rowHeight(i);
}
// set the minimum size of the table to whatever we got
timeTable->setMinimumSize(tableWidth, tableHeight);
setLayout(hBoxLayout);

View file

@ -270,9 +270,6 @@ void NodeList::reset() {
if (_dtlsSocket) {
disconnect(_dtlsSocket, 0, this, 0);
}
// reset the connection times
_lastConnectionTimes.clear();
}
void NodeList::addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd) {
@ -673,6 +670,13 @@ void NodeList::flagTimeForConnectionStep(NodeList::ConnectionStep connectionStep
}
void NodeList::flagTimeForConnectionStep(NodeList::ConnectionStep connectionStep, quint64 timestamp) {
QWriteLocker writeLock(&_connectionTimeLock);
if (connectionStep == NodeList::ConnectionStep::LookupAddress) {
// we clear the current times if the user just fired off a lookup
_lastConnectionTimes.clear();
}
// we only add a timestamp on the first call for each NodeList::ConnectionStep
if (!_lastConnectionTimes.contains(connectionStep)) {
_lastConnectionTimes[connectionStep] = timestamp;

View file

@ -84,8 +84,10 @@ public:
int processDomainServerList(const QByteArray& packet);
const QMap<ConnectionStep, quint64> getLastConnectionTimes() const { return _lastConnectionTimes; }
const QMap<ConnectionStep, quint64> getLastConnectionTimes() const
{ QReadLocker readLock(&_connectionTimeLock); return _lastConnectionTimes; }
void flagTimeForConnectionStep(NodeList::ConnectionStep connectionStep);
void resetConnectionTimes() { QWriteLocker writeLock(&_connectionTimeLock); _lastConnectionTimes.clear(); }
void setAssignmentServerSocket(const HifiSockAddr& serverSocket) { _assignmentServerSocket = serverSocket; }
void sendAssignment(Assignment& assignment);
@ -128,6 +130,7 @@ private:
bool _hasCompletedInitialSTUNFailure;
unsigned int _stunRequestsSinceSuccess;
mutable QReadWriteLock _connectionTimeLock { };
QMap<ConnectionStep, quint64> _lastConnectionTimes;
friend class Application;