00001 #ifndef _MEM_ARENA_H_ 00002 #define _MEM_ARENA_H_ 00003 00004 #define USE_BTREE 1 00005 00006 #if USE_BTREE 00007 00008 /* b-tree definitions */ 00009 #define TREE_NODE_SIZE 128 /* a power of 2 is probably best */ 00010 #define TREE_NODE_MID 63 /* must be ceiling(TREE_NODE_SIZE / 2) - 1 */ 00011 00012 /* linked list definitions */ 00013 #define LIST_ARRAY_SIZE 64 00014 00015 /* doubly-linked list node */ 00016 struct _dllnode { 00017 struct _dllnode *previous; 00018 struct _slotblock *sb; 00019 struct _dllnode *next; 00020 }; 00021 00022 /* slotblock */ 00023 struct _slotblock { 00024 CmiInt8 startslot; 00025 CmiInt8 nslots; 00026 struct _dllnode *listblock; 00027 }; 00028 00029 typedef struct _dllnode dllnode; 00030 typedef struct _slotblock slotblock; 00031 00032 /* b-tree node */ 00033 struct _btreenode { 00034 int num_blocks; 00035 slotblock blocks[TREE_NODE_SIZE]; 00036 struct _btreenode *child[TREE_NODE_SIZE + 1]; 00037 }; 00038 typedef struct _btreenode btreenode; 00039 00040 /* slotset */ 00041 typedef struct _slotset { 00042 btreenode *btree_root; 00043 dllnode *list_array[LIST_ARRAY_SIZE]; 00044 } slotset; 00045 00046 #else 00047 00048 typedef struct _slotblock 00049 { 00050 CmiInt8 startslot; 00051 CmiInt8 nslots; 00052 } slotblock; 00053 00054 typedef struct _slotset 00055 { 00056 int maxbuf; 00057 slotblock *buf; 00058 CmiInt8 emptyslots; 00059 } slotset; 00060 00061 #endif 00062 00063 slotset *new_slotset(CmiInt8 startslot, CmiInt8 nslots); 00064 CmiInt8 get_slots(slotset *ss, CmiInt8 nslots); 00065 void grab_slots(slotset *ss, CmiInt8 sslot, CmiInt8 nslots); 00066 void free_slots(slotset *ss, CmiInt8 sslot, CmiInt8 nslots); 00067 00068 #endif