MemArena: Free memory for 64-bit machines
Make the logic here a lot simpler. Patch contributed by Google Code user plbl4ster.
This commit is contained in:
parent
9c27fedd6d
commit
3380e47ca7
|
@ -20,6 +20,7 @@
|
|||
#include <linux/ashmem.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <set>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
static const char* ram_temp_file = "/tmp/gc_mem.tmp";
|
||||
|
@ -214,27 +215,7 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32
|
|||
|
||||
bail:
|
||||
// Argh! ERROR! Free what we grabbed so far so we can try again.
|
||||
for (int j = 0; j <= i; j++)
|
||||
{
|
||||
SKIP(flags, views[i].flags);
|
||||
if (views[j].out_ptr_low && *views[j].out_ptr_low)
|
||||
{
|
||||
arena->ReleaseView(*views[j].out_ptr_low, views[j].size);
|
||||
*views[j].out_ptr_low = NULL;
|
||||
}
|
||||
if (*views[j].out_ptr)
|
||||
{
|
||||
#ifdef _M_X64
|
||||
arena->ReleaseView(*views[j].out_ptr, views[j].size);
|
||||
#else
|
||||
if (!(views[j].flags & MV_MIRROR_PREVIOUS))
|
||||
{
|
||||
arena->ReleaseView(*views[j].out_ptr, views[j].size);
|
||||
}
|
||||
#endif
|
||||
*views[j].out_ptr = NULL;
|
||||
}
|
||||
}
|
||||
MemoryMap_Shutdown(views, i+1, flags, arena);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -300,15 +281,20 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
|
|||
|
||||
void MemoryMap_Shutdown(const MemoryView *views, int num_views, u32 flags, MemArena *arena)
|
||||
{
|
||||
std::set<void*> freeset;
|
||||
for (int i = 0; i < num_views; i++)
|
||||
{
|
||||
SKIP(flags, views[i].flags);
|
||||
if (views[i].out_ptr_low && *views[i].out_ptr_low)
|
||||
arena->ReleaseView(*views[i].out_ptr_low, views[i].size);
|
||||
if (*views[i].out_ptr && (views[i].out_ptr_low && *views[i].out_ptr != *views[i].out_ptr_low))
|
||||
arena->ReleaseView(*views[i].out_ptr, views[i].size);
|
||||
*views[i].out_ptr = NULL;
|
||||
if (views[i].out_ptr_low)
|
||||
*views[i].out_ptr_low = NULL;
|
||||
const MemoryView* view = &views[i];
|
||||
u8** outptrs[2] = {view->out_ptr_low, view->out_ptr};
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
u8** outptr = outptrs[j];
|
||||
if (outptr && *outptr && !freeset.count(*outptr))
|
||||
{
|
||||
arena->ReleaseView(*outptr, view->size);
|
||||
freeset.insert(*outptr);
|
||||
*outptr = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue