Skip to content
Snippets Groups Projects
Commit 49778974 authored by Philippe Canal's avatar Philippe Canal
Browse files

Give up after too many iteration

parent 32ec47e5
No related branches found
No related tags found
No related merge requests found
...@@ -129,10 +129,21 @@ uint8_t *SectionMemoryManager::allocateSection(MemoryGroup &MemGroup, ...@@ -129,10 +129,21 @@ uint8_t *SectionMemoryManager::allocateSection(MemoryGroup &MemGroup,
}; };
static CheckerType isNotMonotonic = getMonotonicChecker(); static CheckerType isNotMonotonic = getMonotonicChecker();
int count = 0;
if (MemGroup.Near.base() && isNotMonotonic(MB.base(), MemGroup.Near.base())) { if (MemGroup.Near.base() && isNotMonotonic(MB.base(), MemGroup.Near.base())) {
SmallVector<sys::MemoryBlock, 16> MemToDelete; SmallVector<sys::MemoryBlock, 16> MemToDelete;
while (isNotMonotonic(MB.base(), MemGroup.Near.base())) { while (isNotMonotonic(MB.base(), MemGroup.Near.base())) {
if (count > 1000) {
// We make 1000 allocations without getting in good shape, let's
// give up and return the first one we allocated.
MemToDelete.push_back(MB);
MB = MemToDelete.front();
MemToDelete.erase(MemToDelete.begin());
break;
}
// Hold on to the memory until we get an acceptable one // Hold on to the memory until we get an acceptable one
// just so that we are not given it back. // just so that we are not given it back.
MemToDelete.push_back(MB); MemToDelete.push_back(MB);
...@@ -148,6 +159,7 @@ uint8_t *SectionMemoryManager::allocateSection(MemoryGroup &MemGroup, ...@@ -148,6 +159,7 @@ uint8_t *SectionMemoryManager::allocateSection(MemoryGroup &MemGroup,
// FIXME: Add error propagation to the interface. // FIXME: Add error propagation to the interface.
return nullptr; return nullptr;
} }
++count;
} }
for (sys::MemoryBlock &Block : MemToDelete) { for (sys::MemoryBlock &Block : MemToDelete) {
sys::Memory::releaseMappedMemory(Block); sys::Memory::releaseMappedMemory(Block);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment