Changeset 5dcee525 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2007-07-29T13:50:20Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
83a5cba
Parents:
d1e9321
Message:

Replace the threads_btree B+tree with an AVL tree. The new variable is called
threads_tree. For printing list of threads, use the new AVL tree walker
mechanism.

This solves half of ticket #48.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    rd1e9321 r5dcee525  
    5252#include <func.h>
    5353#include <context.h>
    54 #include <adt/btree.h>
     54#include <adt/avl.h>
    5555#include <adt/list.h>
    5656#include <time/clock.h>
     
    8282};
    8383
    84 /** Lock protecting the threads_btree B+tree.
     84/** Lock protecting the threads_tree AVL tree.
    8585 *
    8686 * For locking rules, see declaration thereof.
     
    8888SPINLOCK_INITIALIZE(threads_lock);
    8989
    90 /** B+tree of all threads.
    91  *
    92  * When a thread is found in the threads_btree B+tree, it is guaranteed to
     90/** ALV tree of all threads.
     91 *
     92 * When a thread is found in the threads_tree AVL tree, it is guaranteed to
    9393 * exist as long as the threads_lock is held.
    9494 */
    95 btree_t threads_btree;         
     95avltree_t threads_tree;         
    9696
    9797SPINLOCK_INITIALIZE(tidlock);
     
    213213#endif
    214214
    215         btree_create(&threads_btree);
     215        avltree_create(&threads_tree);
    216216}
    217217
     
    340340        t->fpu_context_engaged = 0;
    341341
     342        avltree_node_initialize(&t->threads_tree_node);
     343        t->threads_tree_node.key = (uintptr_t) t;
     344
    342345        /* might depend on previous initialization */
    343346        thread_create_arch(t); 
     
    369372
    370373        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);
    372375        spinlock_unlock(&threads_lock);
    373376
     
    392395 *
    393396 * Attach the thread structure to the current task and make it visible in the
    394  * threads_btree.
     397 * threads_tree.
    395398 *
    396399 * @param t     Thread to be attached to the task.
     
    415418         */
    416419        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);
    419421        spinlock_unlock(&threads_lock);
    420422       
     
    576578}
    577579
     580static 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
    578605/** Print list of threads debug info */
    579606void thread_print_list(void)
    580607{
    581         link_t *cur;
    582608        ipl_t ipl;
    583609       
     
    591617            "-- ---------- ---------- ---- ---------\n");
    592618
    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);
    624620
    625621        spinlock_unlock(&threads_lock);
     
    638634bool thread_exists(thread_t *t)
    639635{
    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;
    644641}
    645642
Note: See TracChangeset for help on using the changeset viewer.