Fixed the emplace function implementations for stack and queue (#2657)
* Fixed the emplace function implementations for stack and queue Cleaned up several functions in the stack, queue and priority_queue classes that were non-standard or weren't needed. Updated the "style" of the code to use more modern concepts: "typedef" -> "using", empty constructor body -> default keyword. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Replaced the custom implementations of AZStd stack, (proirity)queue Theses classes now have a template alias to the standard library version of the classes Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
0318419932
commit
bb372f05cd
@@ -1688,12 +1688,12 @@ namespace GridMate
|
||||
return; //No connections to update
|
||||
}
|
||||
bool updateRate = false;
|
||||
AZ::u32 minRateBytesPerSecond = m_connByCongestionState.top().m_rate;
|
||||
AZ::u32 minRateBytesPerSecond = m_connByCongestionState.front().m_rate;
|
||||
//const AZ::u32 old = minRateBytesPerSecond; //For debugging
|
||||
|
||||
auto connIt = AZStd::find(m_connByCongestionState.get_container().begin(), m_connByCongestionState.get_container().end(), id);
|
||||
auto connIt = AZStd::find(m_connByCongestionState.begin(), m_connByCongestionState.end(), id);
|
||||
|
||||
if ( connIt == m_connByCongestionState.get_container().end())
|
||||
if ( connIt == m_connByCongestionState.end())
|
||||
{
|
||||
return; //Already disconnected
|
||||
}
|
||||
@@ -1708,11 +1708,11 @@ namespace GridMate
|
||||
|
||||
//If new min or old min increased, rebuild the heap and send an update
|
||||
if (bytesPerSecond < minRateBytesPerSecond
|
||||
|| (id == m_connByCongestionState.top().m_connection && bytesPerSecond > minRateBytesPerSecond))
|
||||
|| (id == m_connByCongestionState.front().m_connection && bytesPerSecond > minRateBytesPerSecond))
|
||||
{
|
||||
updateRate = true;
|
||||
minRateBytesPerSecond = bytesPerSecond;
|
||||
AZStd::make_heap(m_connByCongestionState.get_container().begin(), m_connByCongestionState.get_container().end());
|
||||
AZStd::make_heap(m_connByCongestionState.begin(), m_connByCongestionState.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ namespace GridMate
|
||||
}
|
||||
};
|
||||
static bool k_enableBackPressure;
|
||||
AZStd::priority_queue<RateConnectionPair> m_connByCongestionState; ///< Connections priority queue sorted by congestion window
|
||||
AZStd::vector<RateConnectionPair> m_connByCongestionState; ///< Connections priority queue sorted by congestion window
|
||||
/***
|
||||
* Updates connection's rate in priority and updates send limit
|
||||
*
|
||||
@@ -479,7 +479,9 @@ namespace GridMate
|
||||
}
|
||||
AZ_Assert(carrier, "NULL carrier!");
|
||||
|
||||
m_connByCongestionState.emplace(RateConnectionPair(AZ::u32(1500), id)); //default to 1500Bps (ex 1 Ethernet frame/second minimum)
|
||||
m_connByCongestionState.emplace_back(AZ::u32(1500), id); //default to 1500Bps (ex 1 Ethernet frame/second minimum)
|
||||
// Restore the heap property after pushing back another element
|
||||
AZStd::push_heap(m_connByCongestionState.begin(), m_connByCongestionState.end());
|
||||
}
|
||||
void OnDisconnect(Carrier* carrier, ConnectionID id, CarrierDisconnectReason reason) override
|
||||
{
|
||||
@@ -490,17 +492,17 @@ namespace GridMate
|
||||
}
|
||||
AZ_Assert(carrier, "NULL carrier!");
|
||||
|
||||
auto connIt = AZStd::find(m_connByCongestionState.get_container().begin(), m_connByCongestionState.get_container().end(), id);
|
||||
if (connIt != m_connByCongestionState.get_container().end())
|
||||
auto connIt = AZStd::find(m_connByCongestionState.begin(), m_connByCongestionState.end(), id);
|
||||
if (connIt != m_connByCongestionState.end())
|
||||
{
|
||||
//Since we are using a weakly sorted heap, we need to re-generate when the top is removed
|
||||
bool remake = (connIt == m_connByCongestionState.get_container().begin());
|
||||
bool remake = (connIt == m_connByCongestionState.begin());
|
||||
|
||||
m_connByCongestionState.get_container().erase(connIt);
|
||||
m_connByCongestionState.erase(connIt);
|
||||
|
||||
if (remake)
|
||||
{
|
||||
AZStd::make_heap(m_connByCongestionState.get_container().begin(), m_connByCongestionState.get_container().end());
|
||||
AZStd::make_heap(m_connByCongestionState.begin(), m_connByCongestionState.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user