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>
|
#include <linux/ashmem.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
static const char* ram_temp_file = "/tmp/gc_mem.tmp";
|
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:
|
bail:
|
||||||
// Argh! ERROR! Free what we grabbed so far so we can try again.
|
// Argh! ERROR! Free what we grabbed so far so we can try again.
|
||||||
for (int j = 0; j <= i; j++)
|
MemoryMap_Shutdown(views, i+1, flags, arena);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
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)
|
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++)
|
for (int i = 0; i < num_views; i++)
|
||||||
{
|
{
|
||||||
SKIP(flags, views[i].flags);
|
const MemoryView* view = &views[i];
|
||||||
if (views[i].out_ptr_low && *views[i].out_ptr_low)
|
u8** outptrs[2] = {view->out_ptr_low, view->out_ptr};
|
||||||
arena->ReleaseView(*views[i].out_ptr_low, views[i].size);
|
for (int j = 0; j < 2; j++)
|
||||||
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);
|
u8** outptr = outptrs[j];
|
||||||
*views[i].out_ptr = NULL;
|
if (outptr && *outptr && !freeset.count(*outptr))
|
||||||
if (views[i].out_ptr_low)
|
{
|
||||||
*views[i].out_ptr_low = NULL;
|
arena->ReleaseView(*outptr, view->size);
|
||||||
|
freeset.insert(*outptr);
|
||||||
|
*outptr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue