Changeset 5dcee525 in mainline for kernel/generic/src/proc/thread.c
- Timestamp:
- 2007-07-29T13:50:20Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 83a5cba
- Parents:
- d1e9321
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/thread.c
rd1e9321 r5dcee525 52 52 #include <func.h> 53 53 #include <context.h> 54 #include <adt/ btree.h>54 #include <adt/avl.h> 55 55 #include <adt/list.h> 56 56 #include <time/clock.h> … … 82 82 }; 83 83 84 /** Lock protecting the threads_ btree B+tree.84 /** Lock protecting the threads_tree AVL tree. 85 85 * 86 86 * For locking rules, see declaration thereof. … … 88 88 SPINLOCK_INITIALIZE(threads_lock); 89 89 90 /** B+tree of all threads.91 * 92 * When a thread is found in the threads_ btree B+tree, it is guaranteed to90 /** ALV tree of all threads. 91 * 92 * When a thread is found in the threads_tree AVL tree, it is guaranteed to 93 93 * exist as long as the threads_lock is held. 94 94 */ 95 btree_t threads_btree;95 avltree_t threads_tree; 96 96 97 97 SPINLOCK_INITIALIZE(tidlock); … … 213 213 #endif 214 214 215 btree_create(&threads_btree);215 avltree_create(&threads_tree); 216 216 } 217 217 … … 340 340 t->fpu_context_engaged = 0; 341 341 342 avltree_node_initialize(&t->threads_tree_node); 343 t->threads_tree_node.key = (uintptr_t) t; 344 342 345 /* might depend on previous initialization */ 343 346 thread_create_arch(t); … … 369 372 370 373 spinlock_lock(&threads_lock); 371 btree_remove(&threads_btree, (btree_key_t) ((uintptr_t ) t), NULL);374 avltree_delete(&threads_tree, &t->threads_tree_node); 372 375 spinlock_unlock(&threads_lock); 373 376 … … 392 395 * 393 396 * Attach the thread structure to the current task and make it visible in the 394 * threads_ btree.397 * threads_tree. 395 398 * 396 399 * @param t Thread to be attached to the task. … … 415 418 */ 416 419 spinlock_lock(&threads_lock); 417 btree_insert(&threads_btree, (btree_key_t) ((uintptr_t) t), (void *) t, 418 NULL); 420 avltree_insert(&threads_tree, &t->threads_tree_node); 419 421 spinlock_unlock(&threads_lock); 420 422 … … 576 578 } 577 579 580 static void thread_walker(avltree_node_t *node) 581 { 582 thread_t *t; 583 584 t = avltree_get_instance(node, thread_t, threads_tree_node); 585 586 uint64_t cycles; 587 char suffix; 588 order(t->cycles, &cycles, &suffix); 589 590 printf("%-6llu %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ", 591 t->tid, t->name, t, thread_states[t->state], t->task, 592 t->task->context, t->thread_code, t->kstack, cycles, suffix); 593 594 if (t->cpu) 595 printf("%-4zd", t->cpu->id); 596 else 597 printf("none"); 598 599 if (t->state == Sleeping) 600 printf(" %#10zx", t->sleep_queue); 601 602 printf("\n"); 603 } 604 578 605 /** Print list of threads debug info */ 579 606 void thread_print_list(void) 580 607 { 581 link_t *cur;582 608 ipl_t ipl; 583 609 … … 591 617 "-- ---------- ---------- ---- ---------\n"); 592 618 593 for (cur = threads_btree.leaf_head.next; 594 cur != &threads_btree.leaf_head; cur = cur->next) { 595 btree_node_t *node; 596 unsigned int i; 597 598 node = list_get_instance(cur, btree_node_t, leaf_link); 599 for (i = 0; i < node->keys; i++) { 600 thread_t *t; 601 602 t = (thread_t *) node->value[i]; 603 604 uint64_t cycles; 605 char suffix; 606 order(t->cycles, &cycles, &suffix); 607 608 printf("%-6llu %-10s %#10zx %-8s %#10zx %-3ld %#10zx " 609 "%#10zx %9llu%c ", t->tid, t->name, t, 610 thread_states[t->state], t->task, t->task->context, 611 t->thread_code, t->kstack, cycles, suffix); 612 613 if (t->cpu) 614 printf("%-4zd", t->cpu->id); 615 else 616 printf("none"); 617 618 if (t->state == Sleeping) 619 printf(" %#10zx", t->sleep_queue); 620 621 printf("\n"); 622 } 623 } 619 avltree_walk(&threads_tree, thread_walker); 624 620 625 621 spinlock_unlock(&threads_lock); … … 638 634 bool thread_exists(thread_t *t) 639 635 { 640 btree_node_t *leaf; 641 642 return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t), 643 &leaf) != NULL; 636 avltree_node_t *node; 637 638 node = avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) t)); 639 640 return node != NULL; 644 641 } 645 642
Note:
See TracChangeset
for help on using the changeset viewer.