Changeset 2810636 in mainline
- Timestamp:
- 2006-04-09T16:29:26Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 33472fa
- Parents:
- 7f7859b9
- Location:
- generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/adt/btree.h
r7f7859b9 r2810636 77 77 }; 78 78 79 extern void btree_init(void); 80 79 81 extern void btree_create(btree_t *t); 80 82 extern void btree_destroy(btree_t *t); -
generic/src/adt/btree.c
r7f7859b9 r2810636 29 29 /* 30 30 * This B-tree has the following properties: 31 * - it is a ballanced 2-3-4-5 tree (i.e. BTREE_M = 5)31 * - it is a ballanced 3-4-5 tree (i.e. BTREE_M = 5) 32 32 * - values (i.e. pointers to values) are stored only in leaves 33 33 * - leaves are linked in a list … … 75 75 #define MEDIAN_HIGH(n) ((n)->key[MEDIAN_HIGH_INDEX((n))]); 76 76 77 static slab_cache_t *btree_node_slab; 78 79 /** Initialize B-trees. */ 80 void btree_init(void) 81 { 82 btree_node_slab = slab_cache_create("btree_node_slab", sizeof(btree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); 83 } 84 77 85 /** Create empty B-tree. 78 86 * … … 82 90 { 83 91 list_initialize(&t->leaf_head); 84 t->root = (btree_node_t *) malloc(sizeof(btree_node_t), 0);92 t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0); 85 93 node_initialize(t->root); 86 94 list_append(&t->root->leaf_link, &t->leaf_head); … … 91 99 { 92 100 ASSERT(!t->root->keys); 93 free(t->root);101 slab_free(btree_node_slab, t->root); 94 102 } 95 103 … … 162 170 * We split the root node. Create new root. 163 171 */ 164 t->root = (btree_node_t *) malloc(sizeof(btree_node_t), 0);172 t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0); 165 173 node->parent = t->root; 166 174 rnode->parent = t->root; … … 215 223 t->root = node->subtree[0]; 216 224 t->root->parent = NULL; 217 free(node);225 slab_free(btree_node_slab, node); 218 226 } else { 219 227 /* … … 270 278 idx = find_key_by_subtree(parent, rnode, true); 271 279 ASSERT((int) idx != -1); 272 free(rnode);280 slab_free(btree_node_slab, rnode); 273 281 _btree_remove(t, parent->key[idx], parent); 274 282 } … … 563 571 * Allocate and initialize new right sibling. 564 572 */ 565 rnode = (btree_node_t *) malloc(sizeof(btree_node_t), 0);573 rnode = (btree_node_t *) slab_alloc(btree_node_slab, 0); 566 574 node_initialize(rnode); 567 575 rnode->parent = node->parent; -
generic/src/main/main.c
r7f7859b9 r2810636 58 58 #include <ipc/ipc.h> 59 59 #include <macros.h> 60 #include <adt/btree.h> 60 61 61 62 #ifdef CONFIG_SMP … … 169 170 frame_init(); /* Initialize at least 1 memory segment big enough for slab to work */ 170 171 slab_cache_init(); 172 btree_init(); 171 173 as_init(); 172 174 page_init();
Note:
See TracChangeset
for help on using the changeset viewer.