This commit is contained in:
Julian Barathieu 2019-05-27 19:21:11 +02:00
parent 3ba84e3fe3
commit 35be48eec4
2 changed files with 102 additions and 32 deletions

View File

@ -47,7 +47,6 @@ struct ListHead_t
struct ListNode_t
{
void *data;
ListHead_t *head;
ListNode_t *prev;
ListNode_t *next;
@ -71,22 +70,6 @@ static inline ListHead_t
return head;
}
// Create a node
//
static inline ListNode_t
*ExCreateNode(void *data)
{
ListNode_t *node = malloc(sizeof(ListNode_t));
if (node == NULL) return NULL;
node->data = data;
node->head = NULL;
node->prev = node->next = NULL;
return node;
}
//
// Prepend node at beginning of list
//
@ -228,16 +211,6 @@ leave:
return head;
}
//
// Free a node
//
static inline void
ExDestroyNode(ListNode_t *node)
{
assert(node);
free(node);
}
//
// Free a list head
//
@ -248,11 +221,6 @@ ExDestroyListHead(ListHead_t *head)
free(head);
}
//
// Access a node's data
//
#define ExGetNodeData(node, type) ((type)(node)->data)
//------------------------------------------//
#ifdef __cplusplus

102
include/mm/malloc.h Normal file
View File

@ -0,0 +1,102 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Memory allocation functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KERNEL_H
#include <kernel.h>
#endif
#ifndef _LIB_LIST_H
#include <lib/list.h>
#endif
#ifndef _MM_MALLOC_H
#define _MM_MALLOC_H
#ifndef PAGESIZE
#define PAGESIZE 4096
#endif
typedef struct Cache_t Cache_t;
typedef struct Pool_t Pool_t;
// Operation on objects
typedef void (*ObjCtor_t)(Cache_t *cache,
Pool_t *pool,
void *obj);
//
// A cache containing many pools
//
struct Cache_t
{
// Synchronization
Spinlock_t lock;
// Cache name
char name[64];
// Size of each object
size_t objsize;
// Number of objects allocated
size_t objused;
// Number of available objects including unused
size_t objtotal;
// Number of objects per pool
size_t objperpool;
// Object constructor
ObjOper_t *ctor;
// Object destructor
ObjOper_t *dtor;
// Object pools without any allocated object
ListHead_t *freepools;
// Object pools containing some allocated objects
ListHead_t *usedpools;
// Objects pools containing no unallocated object
ListHead_t *fullpools;
};
//
// A pool of allocable objects
// Takes a fixed amount of pages
//
struct Pool_t
{
};
//
// Allocates memory from the kernel heap
//
void *kmalloc(size_t req, uint flags);
void *kmemalign(size_t req, uint align, uint flags);
#endif