view runtime/fixed_alloc.h @ 69:d0ce696786cc

Clean up debug print statements a bit. Fix bug that prevented workers that took no inputs from working. Remove workaround in Array for said bug.
author Mike Pavone <pavone@retrodev.com>
date Wed, 16 Jun 2010 04:36:08 +0000
parents d1569087348f
children 5a195ee08eac
line wrap: on
line source

#ifndef FIXED_ALLOC_H_
#define FIXED_ALLOC_H_

#include <stddef.h>
#include "plat_types.h"
#include "block_alloc.h"

#define GET_BLOCK(ptr) ((void*)(((uintptr_t)(ptr))&(~((uintptr_t)(BLOCK_SIZE-1)))))

#define MAX_SIZE   (BLOCK_SIZE/32)
#define STRIDE     (BLOCK_SIZE/1024)
#define MIN_SIZE   (BLOCK_SIZE/1024)
#define MAX_FREE   64

#define ADJUST_SIZE(requested) (((requested)+(STRIDE-1)) & (~(STRIDE-1)))


#pragma pack(push,1)
typedef struct mem_block {
	struct mem_block *next;
	struct mem_block *last;
	uint16_t         numfree;
	uint16_t          firstfree;
	uint8_t          bitmap[1];
} mem_block;
#pragma pack(pop)

//num_elements = (BLOCK_SIZE - sizeof(mem_block)+1)*8/(sizeof(element)*8+1)
typedef struct {
	mem_block *freelist;
	mem_block *inuse[(MAX_SIZE-MIN_SIZE)/STRIDE];
	uint32_t freecount;
} mem_manager;

void fixed_alloc_init();
mem_manager * new_mem_manager();
void * falloc(size_t size, mem_manager * manager);
void ffree(void * ptr, size_t size, mem_manager * manager);

#endif //FIXED_ALLOC_H_