blob: 1af8dfbd87cc1eec38bb0553617e22ef418f1859 (
plain) (
tree)
|
|
#ifndef JOVE_LIB_BUDDYMAP_H
#define JOVE_LIB_BUDDYMAP_H 1
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#define BUDDY_BLOCK_BYTES sizeof(intmax_t)
#define BUDDY_BLOCK_BITS (BUDDY_BLOCK_BYTES * 8)
#define BUDDY_BITS_FOR(range) (range * 2)
#define BUDDY_BLOCKS_FOR(range) (BUDDY_BITS_FOR(range) / BUDDY_BLOCK_BITS)
struct BuddyMap
{
size_t orders;
size_t bits;
size_t free;
uintmax_t **blocks;
};
#define BUDDY_BIT_PARTIAL 0
#define BUDDY_BIT_FULL 1
bool buddy_bit_test(struct BuddyMap *map, size_t l, size_t i);
void buddy_bit_mark(struct BuddyMap *map, size_t l, size_t i);
void buddy_bit_free(struct BuddyMap *map, size_t l, size_t i);
void buddy_mark_range(struct BuddyMap *map, size_t start, size_t end);
void buddy_free_range(struct BuddyMap *map, size_t start, size_t end);
intmax_t buddy_alloc(struct BuddyMap *map, size_t length);
void buddy_free(struct BuddyMap *map, size_t i, size_t length);
#endif
|