diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-16 22:58:05 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-16 22:58:05 +0200 |
commit | 54d76800cf8010434065556e12f693b101383d8b (patch) | |
tree | 5388f108f5a461fac83f593c19b85533f1a0e468 /Source/Kernel/MemoryManager/Heap.class.cpp | |
parent | 518d722a88a62d81150e54b8ae02be7176171ccf (diff) | |
parent | 4d5348a49f54d95c0271c8f9c4ef01c005d6b74b (diff) | |
download | Melon-54d76800cf8010434065556e12f693b101383d8b.tar.gz Melon-54d76800cf8010434065556e12f693b101383d8b.zip |
Merge branch 'heap_class'
Conflicts:
Source/Kernel/Melon.ke
Diffstat (limited to 'Source/Kernel/MemoryManager/Heap.class.cpp')
-rw-r--r-- | Source/Kernel/MemoryManager/Heap.class.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Source/Kernel/MemoryManager/Heap.class.cpp b/Source/Kernel/MemoryManager/Heap.class.cpp index f5bbe0a..7331cd0 100644 --- a/Source/Kernel/MemoryManager/Heap.class.cpp +++ b/Source/Kernel/MemoryManager/Heap.class.cpp @@ -1,7 +1,7 @@ #include "Heap.class.h" #include <MemoryManager/PageDirectory.class.h> -Heap::Heap() { +Heap::Heap() : m_mutex(MUTEX_FALSE) { m_usable = false; m_index.data = 0; m_index.size = 0; @@ -12,6 +12,8 @@ Heap::~Heap() { } void Heap::create(u32int start, u32int size, u32int idxsize, PageDirectory* pagedir, bool user, bool rw) { + if (m_usable) return; + if (start & 0x0FFF) start = (start & 0xFFFFF000) + 0x1000; if (size & 0x0FFF) size = (size & 0xFFFFF000) + 0x1000; m_start = start + idxsize; //m_start is start of real data, start is start of index. @@ -42,6 +44,8 @@ void Heap::create(u32int start, u32int size, u32int idxsize, PageDirectory* page m_usable = true; m_free = (m_end - m_start); + + m_mutex.unlock(); } void Heap::expand(u32int quantity) { @@ -113,6 +117,8 @@ void Heap::contract() { //Automatically work out how much we can contract } void *Heap::alloc(u32int sz, bool no_expand) { + m_mutex.waitLock(); + u32int newsize = sz + sizeof(heap_header_t) + sizeof(heap_footer_t); u32int iterator = 0; while (iterator < m_index.size) { @@ -120,8 +126,12 @@ void *Heap::alloc(u32int sz, bool no_expand) { iterator++; } if (iterator == m_index.size) { //No hole is big enough - if (no_expand) return 0; + if (no_expand) { + m_mutex.unlock(); + return 0; + } expand((sz & 0xFFFFF000) + 0x1000); + m_mutex.unlock(); return alloc(sz, true); //Recurse call } @@ -152,6 +162,8 @@ void *Heap::alloc(u32int sz, bool no_expand) { m_free -= loc->size; + m_mutex.unlock(); + return (void*)((u32int)loc + sizeof(heap_header_t)); } @@ -162,6 +174,8 @@ void Heap::free(void *ptr) { heap_footer_t *footer = (heap_footer_t*)((u32int)header + header->size - sizeof(heap_footer_t)); if (header->magic != HEAP_MAGIC or footer->magic != HEAP_MAGIC) return; + m_mutex.waitLock(); + m_free += header->size; //Unify left @@ -192,4 +206,6 @@ void Heap::free(void *ptr) { header->size >= 0x2000 and (m_end - m_start > HEAP_MIN_SIZE)) { contract(); } + + m_mutex.unlock(); } |