@@ -501,6 +501,11 @@ namespace AZ::IO
501
501
502
502
auto Scheduler::Thread_PrioritizeRequests (const FileRequest* first, const FileRequest* second) const -> Order
503
503
{
504
+ if (first == second)
505
+ {
506
+ return Order::Equal;
507
+ }
508
+
504
509
// Sort by order priority of the command in the request. This allows to for instance have cancel request
505
510
// always happen before any other requests.
506
511
auto order = [](auto && args)
@@ -544,7 +549,7 @@ namespace AZ::IO
544
549
}
545
550
546
551
// If neither has started and have the same priority, prefer to start the closest deadline.
547
- return firstRead->m_deadline <= secondRead->m_deadline ? Order::FirstRequest : Order::SecondRequest;
552
+ return firstRead->m_deadline < secondRead->m_deadline ? Order::FirstRequest : Order::SecondRequest;
548
553
}
549
554
550
555
// Check if one of the requests is in panic and prefer to prioritize that request
@@ -593,7 +598,7 @@ namespace AZ::IO
593
598
s64 secondReadOffset = AZStd::visit (offset, second->GetCommand ());
594
599
s64 firstSeekDistance = abs (aznumeric_cast<s64>(m_threadData.m_lastFileOffset ) - firstReadOffset);
595
600
s64 secondSeekDistance = abs (aznumeric_cast<s64>(m_threadData.m_lastFileOffset ) - secondReadOffset);
596
- return firstSeekDistance <= secondSeekDistance ? Order::FirstRequest : Order::SecondRequest;
601
+ return firstSeekDistance < secondSeekDistance ? Order::FirstRequest : Order::SecondRequest;
597
602
}
598
603
599
604
// Prefer to continue in the same file so prioritize the request that's in the same file
@@ -625,6 +630,13 @@ namespace AZ::IO
625
630
" Scheduler::Thread_ScheduleRequests - Sorting %i requests" , m_context.GetNumPreparedRequests ());
626
631
auto sorter = [this ](const FileRequest* lhs, const FileRequest* rhs) -> bool
627
632
{
633
+ if (lhs == rhs)
634
+ {
635
+ // AZStd::sort may compare an element to itself;
636
+ // it's required this condition remain consistent and return false.
637
+ return false ;
638
+ }
639
+
628
640
Order order = Thread_PrioritizeRequests (lhs, rhs);
629
641
switch (order)
630
642
{
0 commit comments