Improved get_free_resource_slot()
Table now tries to expand itself when no available slots are left
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "pageallocator.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ struct resource_t
|
|||||||
struct resource_table_t
|
struct resource_table_t
|
||||||
{
|
{
|
||||||
struct resource_t *array;
|
struct resource_t *array;
|
||||||
size_t capacity;
|
struct resource_t *limit;
|
||||||
};
|
};
|
||||||
|
|
||||||
int find_resource_slot(struct resource_table_t *table);
|
int get_free_resource_slot(struct resource_table_t *table, struct page_stack_t *page_stack);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ int load_module(struct kernel_t *kernel, struct module_t *module)
|
|||||||
}
|
}
|
||||||
load_offset += page_size;
|
load_offset += page_size;
|
||||||
}
|
}
|
||||||
int index = find_resource_slot(kernel);
|
int index = get_free_resource_slot(kernel, kernel->page_stack);
|
||||||
if(index < 0)
|
if(index < 0)
|
||||||
{
|
{
|
||||||
panic("no space left in resource table for module");
|
panic("no space left in resource table for module");
|
||||||
|
|||||||
@@ -1,13 +1,31 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
#include "mmgr.h"
|
||||||
|
#include "allocator.h"
|
||||||
|
#include "types/status.h"
|
||||||
|
|
||||||
int find_resource_slot(struct resource_table_t *table)
|
int get_free_resource_slot(struct resource_table_t *table, struct page_stack_t *page_stack)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < table->capacity; i++)
|
if(table == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
size_t capacity = table->limit - table->array;
|
||||||
|
for(int i = 0; i < capacity; i++)
|
||||||
{
|
{
|
||||||
if(table->array[i].type == RESOURCE_UNAVAILABLE)
|
if(table->array[i].type == RESOURCE_UNAVAILABLE)
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void *new_limit = allocate_from_bottom(page_size);
|
||||||
|
if(new_limit != NULL)
|
||||||
|
{
|
||||||
|
if(map_page(page_stack, new_limit, reserve_page(page_stack), PAGE_RW) != S_OK)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
table->limit = (struct resource_t*)(new_limit + page_size);
|
||||||
|
return get_free_resource_slot(table, page_stack);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user