1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Fix formatting and remove namespaces in libmaxsi heap.cpp.

What a mess.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-26 19:56:28 +02:00
parent d81cdc09e9
commit 31df7c0c93

View file

@ -54,10 +54,6 @@
typedef uintptr_t addr_t;
#endif
namespace Maxsi
{
namespace Memory
{
//
// This first section is just magic compiler/platform stuff, you should
// skip ahead to the actual algorithm.
@ -77,17 +73,17 @@ namespace Maxsi
extern addr_t wilderness;
#ifdef SORTIX_KERNEL
addr_t GetHeapStart()
static addr_t GetHeapStart()
{
return Sortix::Memory::GetHeapUpper();
}
size_t GetHeapMaxSize()
static size_t GetHeapMaxSize()
{
return Sortix::Memory::GetHeapUpper() - Sortix::Memory::GetHeapLower();
}
void FreeMemory(addr_t where, size_t bytes)
static void FreeMemory(addr_t where, size_t bytes)
{
assert(Sortix::Page::IsAligned(where + bytes));
@ -101,7 +97,7 @@ namespace Maxsi
}
}
bool AllocateMemory(addr_t where, size_t bytes)
static bool AllocateMemory(addr_t where, size_t bytes)
{
assert(Sortix::Page::IsAligned(where + bytes));
@ -130,7 +126,7 @@ namespace Maxsi
return true;
}
bool ExtendHeap(size_t bytesneeded)
static bool ExtendHeap(size_t bytesneeded)
{
#ifdef HEAP_GROWS_DOWNWARDS
addr_t newwilderness = wilderness - bytesneeded;
@ -141,7 +137,7 @@ namespace Maxsi
return AllocateMemory(newwilderness, bytesneeded);
}
#else
addr_t GetHeapStart()
static addr_t GetHeapStart()
{
addr_t base = (addr_t) sbrk(0);
addr_t unaligned = base % ALIGNMENT;
@ -153,13 +149,13 @@ namespace Maxsi
return result;
}
size_t GetHeapMaxSize()
static size_t GetHeapMaxSize()
{
// TODO: A bit of a hack!
return SIZE_MAX;
}
bool ExtendHeap(size_t bytesneeded)
static bool ExtendHeap(size_t bytesneeded)
{
void* newheapend = sbrk(bytesneeded);
return newheapend != (void*) -1UL;
@ -274,7 +270,7 @@ namespace Maxsi
};
// A trailer ro every chunk providing meta-information.
// A trailer to every chunk providing meta-information.
struct Trailer
{
public:
@ -363,7 +359,7 @@ namespace Maxsi
return true;
}
void InsertChunk(Chunk* chunk)
static void InsertChunk(Chunk* chunk)
{
// Insert the chunk into the right bin.
size_t binindex = BSR(chunk->size);
@ -379,7 +375,7 @@ namespace Maxsi
assert(chunk->IsSane());
}
bool ValidateHeap()
static bool ValidateHeap()
{
bool foundbin[NUMBINS];
for ( size_t i = 0; i < NUMBINS; i++ ) { foundbin[i] = false; }
@ -421,7 +417,7 @@ namespace Maxsi
// This is where the actual memory allocation algorithm starts.
//
void Init()
extern "C" void _init_heap()
{
heapstart = GetHeapStart();
heapmaxsize = GetHeapMaxSize();
@ -435,15 +431,10 @@ namespace Maxsi
#endif
}
extern "C" void _init_heap()
{
Init();
}
// Attempts to expand the wilderness such that it contains at least
// bytesneeded bytes. This is done by mapping new pages onto into the
// virtual address-space.
bool ExpandWilderness(size_t bytesneeded)
static bool ExpandWilderness(size_t bytesneeded)
{
if ( bytesneeded <= wildernesssize ) { return true; }
@ -587,7 +578,7 @@ namespace Maxsi
return (void*) result;
}
bool IsLeftmostChunk(Chunk* chunk)
static bool IsLeftmostChunk(Chunk* chunk)
{
#ifdef HEAP_GROWS_DOWNWARDS
return (addr_t) chunk <= wilderness + wildernesssize;
@ -596,7 +587,7 @@ namespace Maxsi
#endif
}
bool IsRightmostChunk(Chunk* chunk)
static bool IsRightmostChunk(Chunk* chunk)
{
#ifdef HEAP_GROWS_DOWNWARDS
return heapstart <= (addr_t) chunk + chunk->size;
@ -606,7 +597,7 @@ namespace Maxsi
}
// Removes a chunk from its bin.
void UnlinkChunk(Chunk* chunk)
static void UnlinkChunk(Chunk* chunk)
{
assert(chunk->IsSane());
Trailer* trailer = chunk->GetTrailer();
@ -636,7 +627,7 @@ namespace Maxsi
}
// Transforms a chunk and its neighbors into a single chunk if possible.
void UnifyNeighbors(Chunk** chunk)
static void UnifyNeighbors(Chunk** chunk)
{
if ( !IsLeftmostChunk(*chunk) )
{
@ -726,5 +717,3 @@ namespace Maxsi
free(ptr);
return newptr;
}
}
}