42,13 → 42,22 |
|
/** Buddy system operations to be implemented by each implementation. */ |
struct buddy_system_operations { |
link_t *(* find_buddy)(buddy_system_t *, link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */ |
link_t *(* bisect)(buddy_system_t *, link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */ |
link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */ |
void (*set_order)(buddy_system_t *, link_t *, uint8_t); /**< Set order of block passed as argument. */ |
uint8_t (*get_order)(buddy_system_t *, link_t *); /**< Return order of block passed as argument. */ |
void (*mark_busy)(buddy_system_t *, link_t *); /**< Mark block as busy. */ |
void (*mark_available)(buddy_system_t *, link_t *); /**< Mark block as available. */ |
/** Return pointer to left-side or right-side buddy for block passed as |
* argument. */ |
link_t *(* find_buddy)(buddy_system_t *, link_t *); |
/** Bisect the block passed as argument and return pointer to the new |
* right-side buddy. */ |
link_t *(* bisect)(buddy_system_t *, link_t *); |
/** Coalesce two buddies into a bigger block. */ |
link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); |
/** Set order of block passed as argument. */ |
void (*set_order)(buddy_system_t *, link_t *, uint8_t); |
/** Return order of block passed as argument. */ |
uint8_t (*get_order)(buddy_system_t *, link_t *); |
/** Mark block as busy. */ |
void (*mark_busy)(buddy_system_t *, link_t *); |
/** Mark block as available. */ |
void (*mark_available)(buddy_system_t *, link_t *); |
/** Find parent of block that has given order */ |
link_t *(* find_block)(buddy_system_t *, link_t *, uint8_t); |
void (* print_id)(buddy_system_t *, link_t *); |
55,14 → 64,15 |
}; |
|
struct buddy_system { |
uint8_t max_order; /**< Maximal order of block which can be stored by buddy system. */ |
/** Maximal order of block which can be stored by buddy system. */ |
uint8_t max_order; |
link_t *order; |
buddy_system_operations_t *op; |
void *data; /**< Pointer to be used by the implementation. */ |
/** Pointer to be used by the implementation. */ |
void *data; |
}; |
|
extern void buddy_system_create(buddy_system_t *b, |
uint8_t max_order, |
extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, |
buddy_system_operations_t *op, void *data); |
extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); |
extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); |