We don't need buddy allocator...

This commit is contained in:
secXsQuared 2016-06-19 21:11:06 -07:00
parent 8ef4b18684
commit 59bac9bf2c
2 changed files with 38 additions and 14 deletions

View File

@ -22,7 +22,7 @@ static void _set_salloc_header_size(_salloc_header *header, uint32_t size)
size <<= ALLOC_FLAG_NUM;
// clear ALLOC_FLAG_NUM-th to 31-th bits
header->size &= ~bit_field_mask_32(ALLOC_FLAG_NUM, 31);
header->size &= ~(uint32_t) bit_field_mask(ALLOC_FLAG_NUM, 31);
// set bits
header->size |= size;
return;
@ -35,19 +35,19 @@ static uint32_t _read_salloc_header_size(_salloc_header *header)
static uint32_t _read_salloc_header_flag(_salloc_header *header, uint32_t bit)
{
return (header->flags & bit_mask_32(bit)) == 0 ? 0 : 1;
return (header->flags & (uint32_t) bit_mask(bit)) == 0 ? 0 : 1;
}
static void _set_salloc_header_flag(_salloc_header *header, uint32_t bit, uint32_t value)
{
value &= bit_mask_32(0);
value &= (uint32_t) bit_mask(0);
if (value == 1)
{
header->flags |= bit_mask_32(bit);
header->flags |= (uint32_t) bit_mask(bit);
}
else
{
header->flags &= ~bit_mask_32(bit);
header->flags &= ~(uint32_t) bit_mask(bit);
}
return;
}

View File

@ -9,24 +9,48 @@
#include "s_type.h"
#include "s_def.h"
static inline uint64_t KAPI bit_mask_64(uint32_t bit)
static inline uint64_t KAPI bit_mask(uint32_t bit)
{
return (uint64_t)1 << bit;
}
static inline uint32_t KAPI bit_mask_32(uint32_t bit)
{
return (uint32_t)1 << bit;
}
static inline uint64_t KAPI bit_field_mask_64(uint32_t low, uint32_t high)
static inline uint64_t KAPI bit_field_mask(uint32_t low, uint32_t high)
{
return ~(~(uint64_t)0 << high << 1) << low;
}
static inline uint32_t KAPI bit_field_mask_32(uint32_t low, uint32_t high)
static inline void KAPI bit_map_set(void* bit_map, uint64_t bit)
{
return ~(~(uint32_t)0 << high << 1) << low;
if(bit_map != NULL)
{
uint64_t quot = bit >> 3;
uint32_t rmd = (uint32_t)(bit & bit_field_mask(0,2));
*((uint8_t*)(bit_map) + quot) |= (uint8_t)bit_mask(rmd);
}
}
static inline void KAPI bit_map_clear(void* bit_map, uint64_t bit)
{
if(bit_map != NULL)
{
uint64_t quot = bit >> 3;
uint32_t rmd = (uint32_t)(bit & bit_field_mask(0,2));
*((uint8_t*)(bit_map) + quot) &= ~(uint8_t)bit_mask(rmd);
}
}
static inline uint32_t KAPI bit_map_read(void* bit_map, uint64_t bit)
{
if(bit_map != NULL)
{
uint64_t quot = bit >> 3;
uint32_t rmd = (uint32_t)(bit & bit_field_mask(0,2));
return (*((uint8_t*)(bit_map) + quot) & (uint8_t)bit_mask(rmd)) == 0 ? 0 : 1;
}
return 0;
}
#endif