NOT working balloc
This commit is contained in:
parent
f6e21df5d2
commit
4410fb50fa
|
@ -0,0 +1,69 @@
|
|||
#include <balloc.h>
|
||||
#include "linked_list.h"
|
||||
#include "balloc.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
linked_list_node_t list_node;
|
||||
} balloc_header_t;
|
||||
|
||||
static inline uint32_t _get_min_granularity()
|
||||
{
|
||||
return sizeof(balloc_header_t);
|
||||
}
|
||||
|
||||
static inline int32_t _order_of_two(uint32_t num)
|
||||
{
|
||||
int32_t result = -1;
|
||||
if(num == 1)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else if(num % 2 == 0 && num != 0)
|
||||
{
|
||||
result = 1;
|
||||
while((num >> result) != 1)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int32_t _get_max_order(uint32_t size, uint32_t granularity)
|
||||
{
|
||||
if(size == 0 || granularity == 0 || granularity > size || size % granularity != 0)
|
||||
return -1;
|
||||
return _order_of_two(size/granularity);
|
||||
}
|
||||
|
||||
int32_t balloc_free_list_size(uint32_t size, uint32_t granularity)
|
||||
{
|
||||
int32_t result = _get_max_order(size,granularity);
|
||||
return result == -1 ? (result) : (result) * ((int32_t)sizeof(linked_list_t));
|
||||
}
|
||||
|
||||
int32_t balloc_bit_map_size(uint32_t size, uint32_t granularity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int32_t balloc_init(balloc_desc_t* desc,
|
||||
void* base,
|
||||
uint32_t size,
|
||||
uint32_t granularity)
|
||||
{
|
||||
if( desc == NULL || base == NULL || granularity == 0 || size == 0 ||
|
||||
granularity < _get_min_granularity() ||
|
||||
size < granularity ||
|
||||
size % granularity != 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
desc->size = size;
|
||||
desc->base = base;
|
||||
desc->granularity = granularity;
|
||||
desc->bit_map = bit_map;
|
||||
desc->free_list = free_list;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef _BALLOC_H_
|
||||
#define _BALLOC_H_
|
||||
|
||||
#include "linked_list.h"
|
||||
#include "k_def.h"
|
||||
#include "bit_ops.h"
|
||||
#include "k_type.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void* base;
|
||||
uint32_t size;
|
||||
uint32_t granularity;
|
||||
linked_list_t* free_list;
|
||||
uint32_t* bit_map;
|
||||
} balloc_desc_t;
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue