mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 22:16:58 +02:00
Fix packetlist compilation on VS 2017
This commit is contained in:
parent
3e68018a12
commit
b8ded015c6
2 changed files with 17 additions and 11 deletions
|
@ -15,6 +15,10 @@
|
||||||
|
|
||||||
using namespace udt;
|
using namespace udt;
|
||||||
|
|
||||||
|
PacketQueue::PacketQueue() {
|
||||||
|
_channels.emplace_back(new std::list<PacketPointer>());
|
||||||
|
}
|
||||||
|
|
||||||
MessageNumber PacketQueue::getNextMessageNumber() {
|
MessageNumber PacketQueue::getNextMessageNumber() {
|
||||||
static const MessageNumber MAX_MESSAGE_NUMBER = MessageNumber(1) << MESSAGE_NUMBER_SIZE;
|
static const MessageNumber MAX_MESSAGE_NUMBER = MessageNumber(1) << MESSAGE_NUMBER_SIZE;
|
||||||
_currentMessageNumber = (_currentMessageNumber + 1) % MAX_MESSAGE_NUMBER;
|
_currentMessageNumber = (_currentMessageNumber + 1) % MAX_MESSAGE_NUMBER;
|
||||||
|
@ -24,7 +28,7 @@ MessageNumber PacketQueue::getNextMessageNumber() {
|
||||||
bool PacketQueue::isEmpty() const {
|
bool PacketQueue::isEmpty() const {
|
||||||
LockGuard locker(_packetsLock);
|
LockGuard locker(_packetsLock);
|
||||||
// Only the main channel and it is empty
|
// Only the main channel and it is empty
|
||||||
return (_channels.size() == 1) && _channels.front().empty();
|
return (_channels.size() == 1) && _channels.front()->empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketQueue::PacketPointer PacketQueue::takePacket() {
|
PacketQueue::PacketPointer PacketQueue::takePacket() {
|
||||||
|
@ -34,19 +38,19 @@ PacketQueue::PacketPointer PacketQueue::takePacket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find next non empty channel
|
// Find next non empty channel
|
||||||
if (_channels[nextIndex()].empty()) {
|
if (_channels[nextIndex()]->empty()) {
|
||||||
nextIndex();
|
nextIndex();
|
||||||
}
|
}
|
||||||
auto& channel = _channels[_currentIndex];
|
auto& channel = _channels[_currentIndex];
|
||||||
Q_ASSERT(!channel.empty());
|
Q_ASSERT(!channel->empty());
|
||||||
|
|
||||||
// Take front packet
|
// Take front packet
|
||||||
auto packet = std::move(channel.front());
|
auto packet = std::move(channel->front());
|
||||||
channel.pop_front();
|
channel->pop_front();
|
||||||
|
|
||||||
// Remove now empty channel (Don't remove the main channel)
|
// Remove now empty channel (Don't remove the main channel)
|
||||||
if (channel.empty() && _currentIndex != 0) {
|
if (channel->empty() && _currentIndex != 0) {
|
||||||
channel.swap(_channels.back());
|
channel->swap(*_channels.back());
|
||||||
_channels.pop_back();
|
_channels.pop_back();
|
||||||
--_currentIndex;
|
--_currentIndex;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +65,7 @@ unsigned int PacketQueue::nextIndex() {
|
||||||
|
|
||||||
void PacketQueue::queuePacket(PacketPointer packet) {
|
void PacketQueue::queuePacket(PacketPointer packet) {
|
||||||
LockGuard locker(_packetsLock);
|
LockGuard locker(_packetsLock);
|
||||||
_channels.front().push_back(std::move(packet));
|
_channels.front()->push_back(std::move(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacketQueue::queuePacketList(PacketListPointer packetList) {
|
void PacketQueue::queuePacketList(PacketListPointer packetList) {
|
||||||
|
@ -70,5 +74,6 @@ void PacketQueue::queuePacketList(PacketListPointer packetList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LockGuard locker(_packetsLock);
|
LockGuard locker(_packetsLock);
|
||||||
_channels.push_back(std::move(packetList->_packets));
|
_channels.emplace_back(new std::list<PacketPointer>());
|
||||||
|
_channels.back()->swap(packetList->_packets);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,11 @@ class PacketQueue {
|
||||||
using LockGuard = std::lock_guard<Mutex>;
|
using LockGuard = std::lock_guard<Mutex>;
|
||||||
using PacketPointer = std::unique_ptr<Packet>;
|
using PacketPointer = std::unique_ptr<Packet>;
|
||||||
using PacketListPointer = std::unique_ptr<PacketList>;
|
using PacketListPointer = std::unique_ptr<PacketList>;
|
||||||
using Channel = std::list<PacketPointer>;
|
using Channel = std::unique_ptr<std::list<PacketPointer>>;
|
||||||
using Channels = std::vector<Channel>;
|
using Channels = std::vector<Channel>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
PacketQueue();
|
||||||
void queuePacket(PacketPointer packet);
|
void queuePacket(PacketPointer packet);
|
||||||
void queuePacketList(PacketListPointer packetList);
|
void queuePacketList(PacketListPointer packetList);
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ private:
|
||||||
MessageNumber _currentMessageNumber { 0 };
|
MessageNumber _currentMessageNumber { 0 };
|
||||||
|
|
||||||
mutable Mutex _packetsLock; // Protects the packets to be sent.
|
mutable Mutex _packetsLock; // Protects the packets to be sent.
|
||||||
Channels _channels = Channels(1); // One channel per packet list + Main channel
|
Channels _channels; // One channel per packet list + Main channel
|
||||||
unsigned int _currentIndex { 0 };
|
unsigned int _currentIndex { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue