use a write lock for sync so it can be recursive

This commit is contained in:
Stephen Birarda 2015-08-28 15:17:44 -07:00
parent abffc0317b
commit 20d1244db4
3 changed files with 6 additions and 3 deletions

View file

@ -146,6 +146,9 @@ void Connection::sync() {
auto sinceLastReceive = duration_cast<microseconds>(high_resolution_clock::now() - _lastReceiveTime);
if (sinceLastReceive.count() >= NUM_TIMEOUTS_FOR_EXPIRY * estimatedTimeout()) {
qDebug() << "Connection to" << _destination << "has not received any new data for"
<< NUM_TIMEOUTS_FOR_EXPIRY << "timeouts. It is now considered inactive and will be cleaned up.";
// connection inactive - emit a signal so we will be cleaned up
emit connectionInactive(_destination);

View file

@ -254,14 +254,14 @@ void Socket::connectToSendSignal(const HifiSockAddr& destinationAddr, QObject* r
void Socket::rateControlSync() {
QReadLocker readLocker(&_connectionsMutex);
QWriteLocker writeLocker(&_connectionsMutex);
// enumerate our list of connections and ask each of them to send off periodic ACK packet for rate control
for (auto& connection : _connectionsHash) {
connection.second->sync();
}
readLocker.unlock();
writeLocker.unlock();
if (_synTimer.interval() != _synInterval) {
// if the _synTimer interval doesn't match the current _synInterval (changes when the CC factory is changed)

View file

@ -94,7 +94,7 @@ private:
std::unordered_map<HifiSockAddr, SequenceNumber> _unreliableSequenceNumbers;
std::unordered_map<HifiSockAddr, std::unique_ptr<Connection>> _connectionsHash;
QReadWriteLock _connectionsMutex; // guards concurrent access to connections hashs
QReadWriteLock _connectionsMutex { QReadWriteLock::Recursive }; // guards concurrent access to connections hashs
int _synInterval = 10; // 10ms
QTimer _synTimer;