Changeset b76a2217 in mainline
- Timestamp:
- 2007-07-29T19:17:25Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7fe9c5b
- Parents:
- 83a5cba
- Location:
- kernel/generic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/avl.h
r83a5cba rb76a2217 54 54 typedef uint64_t avltree_key_t; 55 55 56 typedef void (* avltree_walker_t)(avltree_node_t*);56 typedef bool (* avltree_walker_t)(avltree_node_t *, void *); 57 57 58 58 /** AVL tree node structure. */ … … 134 134 extern void avltree_delete(avltree_t *t, avltree_node_t *node); 135 135 extern bool avltree_delete_min(avltree_t *t); 136 extern void avltree_walk(avltree_t *t, avltree_walker_t walker );136 extern void avltree_walk(avltree_t *t, avltree_walker_t walker, void *arg); 137 137 138 138 #endif -
kernel/generic/include/proc/task.h
r83a5cba rb76a2217 42 42 #include <synch/rwlock.h> 43 43 #include <synch/futex.h> 44 #include <adt/avl.h> 44 45 #include <adt/btree.h> 45 46 #include <adt/list.h> … … 57 58 /** Task structure. */ 58 59 typedef struct task { 60 /** Task's linkage for the tasks_tree AVL tree. */ 61 avltree_node_t tasks_tree_node; 62 59 63 /** Task lock. 60 64 * … … 107 111 108 112 SPINLOCK_EXTERN(tasks_lock); 109 extern btree_t tasks_btree;113 extern avltree_t tasks_tree; 110 114 111 115 extern void task_init(void); -
kernel/generic/src/adt/avl.c
r83a5cba rb76a2217 686 686 } 687 687 688 static void _avltree_walk(avltree_node_t *node, avltree_walker_t walker) 688 /** Walk a subtree of an AVL tree in-order and apply a supplied walker on each 689 * visited node. 690 * 691 * @param node Node representing the root of an AVL subtree to be 692 * walked. 693 * @param walker Walker function that will be appliad on each visited 694 * node. 695 * @param arg Argument for the walker. 696 * 697 * @return Zero if the walk should stop or non-zero otherwise. 698 */ 699 static bool _avltree_walk(avltree_node_t *node, avltree_walker_t walker, 700 void *arg) 689 701 { 690 if (node->lft) 691 _avltree_walk(node->lft, walker); 692 walker(node); 693 if (node->rgt) 694 _avltree_walk(node->rgt, walker); 702 if (node->lft) { 703 if (!_avltree_walk(node->lft, walker, arg)) 704 return false; 705 } 706 if (!walker(node, arg)) 707 return false; 708 if (node->rgt) { 709 if (!_avltree_walk(node->rgt, walker, arg)) 710 return false; 711 } 712 return true; 695 713 } 696 714 697 /** Walk the AVL tree and apply the walker function on each visited node. 715 /** Walk the AVL tree in-order and apply the walker function on each visited 716 * node. 698 717 * 699 718 * @param t AVL tree to be walked. 700 719 * @param walker Walker function that will be called on each visited 701 720 * node. 702 */ 703 void avltree_walk(avltree_t *t, avltree_walker_t walker) 721 * @param arg Argument for the walker. 722 */ 723 void avltree_walk(avltree_t *t, avltree_walker_t walker, void *arg) 704 724 { 705 _avltree_walk(t->root, walker );725 _avltree_walk(t->root, walker, arg); 706 726 } 707 727 -
kernel/generic/src/proc/task.c
r83a5cba rb76a2217 47 47 #include <arch.h> 48 48 #include <panic.h> 49 #include <adt/avl.h> 49 50 #include <adt/btree.h> 50 51 #include <adt/list.h> … … 62 63 #endif 63 64 64 /** Spinlock protecting the tasks_ btree B+tree. */65 /** Spinlock protecting the tasks_tree AVL tree. */ 65 66 SPINLOCK_INITIALIZE(tasks_lock); 66 67 67 /** B+tree of active tasks.68 * 69 * The task is guaranteed to exist after it was found in the tasks_ btree as68 /** AVL tree of active tasks. 69 * 70 * The task is guaranteed to exist after it was found in the tasks_tree as 70 71 * long as: 71 72 * @li the tasks_lock is held, … … 75 76 * 76 77 */ 77 btree_t tasks_btree;78 avltree_t tasks_tree; 78 79 79 80 static task_id_t task_counter = 0; … … 87 88 { 88 89 TASK = NULL; 89 btree_create(&tasks_btree); 90 avltree_create(&tasks_tree); 91 } 92 93 /* 94 * The idea behind this walker is to remember a single task different from TASK. 95 */ 96 static bool task_done_walker(avltree_node_t *node, void *arg) 97 { 98 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 99 task_t **tp = (task_t **) arg; 100 101 if (t != TASK) { 102 *tp = t; 103 return false; /* stop walking */ 104 } 105 106 return true; /* continue the walk */ 90 107 } 91 108 … … 103 120 104 121 t = NULL; 105 link_t *cur; 106 for (cur = tasks_btree.leaf_head.next; 107 cur != &tasks_btree.leaf_head; cur = cur->next) { 108 btree_node_t *node; 109 110 node = list_get_instance(cur, btree_node_t, leaf_link); 111 112 unsigned int i; 113 for (i = 0; i < node->keys; i++) { 114 if ((task_t *) node->value[i] != TASK) { 115 t = (task_t *) node->value[i]; 116 break; 117 } 118 } 119 } 122 avltree_walk(&tasks_tree, task_done_walker, &t); 120 123 121 124 if (t != NULL) { … … 188 191 spinlock_lock(&tasks_lock); 189 192 ta->taskid = ++task_counter; 190 btree_insert(&tasks_btree, (btree_key_t) ta->taskid, (void *) ta, NULL); 193 avltree_node_initialize(&ta->tasks_tree_node); 194 ta->tasks_tree_node.key = ta->taskid; 195 avltree_insert(&tasks_tree, &ta->tasks_tree_node); 191 196 spinlock_unlock(&tasks_lock); 192 197 interrupts_restore(ipl); … … 205 210 */ 206 211 spinlock_lock(&tasks_lock); 207 btree_remove(&tasks_btree, t->taskid, NULL);212 avltree_delete(&tasks_tree, &t->tasks_tree_node); 208 213 spinlock_unlock(&tasks_lock); 209 214 … … 311 316 task_t *task_find_by_id(task_id_t id) 312 317 { 313 btree_node_t *leaf; 314 315 return (task_t *) btree_search(&tasks_btree, (btree_key_t) id, &leaf); 318 avltree_node_t *node; 319 320 node = avltree_search(&tasks_tree, (avltree_key_t) id); 321 322 if (node) 323 return avltree_get_instance(node, task_t, tasks_tree_node); 324 return NULL; 316 325 } 317 326 … … 401 410 } 402 411 412 static bool task_print_walker(avltree_node_t *node, void *arg) 413 { 414 task_t *t = avltree_get_instance(node, task_t, tasks_tree_node); 415 int j; 416 417 spinlock_lock(&t->lock); 418 419 uint64_t cycles; 420 char suffix; 421 order(task_get_accounting(t), &cycles, &suffix); 422 423 printf("%-6llu %-10s %-3ld %#10zx %#10zx %9llu%c %7zd %6zd", 424 t->taskid, t->name, t->context, t, t->as, cycles, suffix, 425 t->refcount, atomic_get(&t->active_calls)); 426 for (j = 0; j < IPC_MAX_PHONES; j++) { 427 if (t->phones[j].callee) 428 printf(" %zd:%#zx", j, t->phones[j].callee); 429 } 430 printf("\n"); 431 432 spinlock_unlock(&t->lock); 433 return true; 434 } 435 403 436 /** Print task list */ 404 437 void task_print_list(void) 405 438 { 406 link_t *cur;407 439 ipl_t ipl; 408 440 … … 416 448 "------ ------>\n"); 417 449 418 for (cur = tasks_btree.leaf_head.next; cur != &tasks_btree.leaf_head; 419 cur = cur->next) { 420 btree_node_t *node; 421 unsigned int i; 422 423 node = list_get_instance(cur, btree_node_t, leaf_link); 424 for (i = 0; i < node->keys; i++) { 425 task_t *t; 426 int j; 427 428 t = (task_t *) node->value[i]; 429 430 spinlock_lock(&t->lock); 431 432 uint64_t cycles; 433 char suffix; 434 order(task_get_accounting(t), &cycles, &suffix); 435 436 printf("%-6llu %-10s %-3ld %#10zx %#10zx %9llu%c %7zd " 437 "%6zd", t->taskid, t->name, t->context, t, t->as, 438 cycles, suffix, t->refcount, 439 atomic_get(&t->active_calls)); 440 for (j = 0; j < IPC_MAX_PHONES; j++) { 441 if (t->phones[j].callee) 442 printf(" %zd:%#zx", j, 443 t->phones[j].callee); 444 } 445 printf("\n"); 446 447 spinlock_unlock(&t->lock); 448 } 449 } 450 avltree_walk(&tasks_tree, task_print_walker, NULL); 450 451 451 452 spinlock_unlock(&tasks_lock); -
kernel/generic/src/proc/thread.c
r83a5cba rb76a2217 578 578 } 579 579 580 static void thread_walker(avltree_node_t *node)580 static bool thread_walker(avltree_node_t *node, void *arg) 581 581 { 582 582 thread_t *t; … … 601 601 602 602 printf("\n"); 603 604 return true; 603 605 } 604 606 … … 617 619 "-- ---------- ---------- ---- ---------\n"); 618 620 619 avltree_walk(&threads_tree, thread_walker );621 avltree_walk(&threads_tree, thread_walker, NULL); 620 622 621 623 spinlock_unlock(&threads_lock);
Note:
See TracChangeset
for help on using the changeset viewer.