mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
guard insert/get in SentPacketHistory
This commit is contained in:
parent
1f1eb00c63
commit
cc6b0adb7d
2 changed files with 9 additions and 4 deletions
|
@ -35,10 +35,11 @@ void SentPacketHistory::packetSent(uint16_t sequenceNumber, const NLPacket& pack
|
|||
}
|
||||
_newestSequenceNumber = sequenceNumber;
|
||||
|
||||
QWriteLocker locker(&_packetsLock);
|
||||
_sentPackets.insert(NLPacket::createCopy(packet));
|
||||
}
|
||||
|
||||
const NLPacket* SentPacketHistory::getPacket(uint16_t sequenceNumber) const {
|
||||
const NLPacket* SentPacketHistory::getPacket(uint16_t sequenceNumber) {
|
||||
|
||||
const int UINT16_RANGE = std::numeric_limits<uint16_t>::max() + 1;
|
||||
|
||||
|
@ -48,6 +49,7 @@ const NLPacket* SentPacketHistory::getPacket(uint16_t sequenceNumber) const {
|
|||
if (seqDiff < 0) {
|
||||
seqDiff += UINT16_RANGE;
|
||||
}
|
||||
|
||||
|
||||
QReadLocker locker(&_packetsLock);
|
||||
return _sentPackets.get(seqDiff)->get();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
#define hifi_SentPacketHistory_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <qbytearray.h>
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QReadWriteLock>
|
||||
|
||||
#include "NLPacket.h"
|
||||
#include "RingBufferHistory.h"
|
||||
|
@ -26,9 +28,10 @@ public:
|
|||
SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP);
|
||||
|
||||
void packetSent(uint16_t sequenceNumber, const NLPacket& packet);
|
||||
const NLPacket* getPacket(uint16_t sequenceNumber) const;
|
||||
const NLPacket* getPacket(uint16_t sequenceNumber);
|
||||
|
||||
private:
|
||||
QReadWriteLock _packetsLock { QReadWriteLock::Recursive };
|
||||
RingBufferHistory<std::unique_ptr<NLPacket>> _sentPackets; // circular buffer
|
||||
|
||||
uint16_t _newestSequenceNumber;
|
||||
|
|
Loading…
Reference in a new issue