feat(kcp, pfa): Add kcp::Spinlock class

This commit is contained in:
Daniel Hammer
2025-03-12 19:55:05 +01:00
parent bd8a1fdbca
commit 2b6c2fa827
7 changed files with 57 additions and 5 deletions
+11
View File
@@ -10,6 +10,8 @@
#include <Libraries/Memory.hpp>
#include <Terminal/Terminal.hpp>
#include <CppLib/Spinlock.hpp>
namespace Memory {
PageFrameAllocator::PageFrameAllocator(LargestSection section) {
/* we need the virtual address rather than the physical address, so we call the helper */
@@ -24,6 +26,8 @@ namespace Memory {
}
void* PageFrameAllocator::Allocate() {
Lock.Aquire();
Page* current = head.next;
Page* prev = &head;
@@ -35,11 +39,15 @@ namespace Memory {
if (new_size == 0) {
prev->next = current->next;
Lock.Release();
return (void*)current;
}
else
{
current->size -= 0x1000;
Lock.Release();
return (void*)current_end_addr - 0x1000;
}
}
@@ -48,6 +56,7 @@ namespace Memory {
current = current->next;
}
Lock.Release();
return nullptr;
}
@@ -67,11 +76,13 @@ namespace Memory {
}
void PageFrameAllocator::Free(void* ptr) {
Lock.Aquire();
auto prev_next = head.next;
head.next = (Page*)ptr;
head.next->next = prev_next;
head.next->size = 0x1000;
Lock.Release();
}
void PageFrameAllocator::Free(void* ptr, int n) {
+3 -1
View File
@@ -7,6 +7,8 @@
#pragma once
#include "Memmap.hpp"
#include <CppLib/Spinlock.hpp>
namespace Memory {
class PageFrameAllocator {
struct Page {
@@ -15,7 +17,7 @@ namespace Memory {
};
Page head{};
kcp::Spinlock Lock{};
LargestSection g_section;
public:
PageFrameAllocator(LargestSection section);