Changeset 016acbe in mainline


Ignore:
Timestamp:
2006-04-09T14:58:42Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f6e755
Parents:
203f4c3
Message:

Replace list of all threads with B+tree of all threads.
Add function thread_exists() for querying existence of thread.

Location:
generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • generic/include/proc/thread.h

    r203f4c3 r016acbe  
    3939#include <synch/rwlock.h>
    4040#include <config.h>
     41#include <adt/btree.h>
    4142#include <adt/list.h>
    4243#include <mm/slab.h>
     
    6667        link_t wq_link;                         /**< Wait queue link. */
    6768        link_t th_link;                         /**< Links to threads within containing task. */
    68         link_t threads_link;                    /**< Link to the list of all threads. */
    6969       
    7070        /** Lock protecting thread structure.
     
    131131extern spinlock_t threads_lock;
    132132
    133 extern link_t threads_head;                     /**< List of all threads in the system. */
     133extern btree_t threads_btree;                   /**< B+tree containing all threads. */
    134134
    135135extern void thread_init(void);
     
    144144extern void thread_print_list(void);
    145145extern void thread_destroy(thread_t *t);
     146extern bool thread_exists(thread_t *t);
    146147
    147148/* Fpu context slab cache */
  • generic/src/proc/thread.c

    r203f4c3 r016acbe  
    4242#include <func.h>
    4343#include <context.h>
     44#include <adt/btree.h>
    4445#include <adt/list.h>
    4546#include <typedefs.h>
     
    5960char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
    6061
    61 SPINLOCK_INITIALIZE(threads_lock);      /**< Lock protecting threads_head list. For locking rules, see declaration thereof. */
    62 LIST_INITIALIZE(threads_head);          /**< List of all threads. */
     62/** Lock protecting threads_head list. For locking rules, see declaration thereof. */
     63SPINLOCK_INITIALIZE(threads_lock);
     64btree_t threads_btree;                  /**< B+tree of all threads. */
    6365
    6466SPINLOCK_INITIALIZE(tidlock);
     
    7072#endif
    7173
    72 
    7374/** Thread wrapper
    7475 *
     
    105106        link_initialize(&t->wq_link);
    106107        link_initialize(&t->th_link);
    107         link_initialize(&t->threads_link);
    108108       
    109109#ifdef ARCH_HAS_FPU
     
    161161                                             NULL, NULL, 0);
    162162#endif
    163 }
    164 
     163
     164        btree_create(&threads_btree);
     165}
    165166
    166167/** Make thread ready
     
    209210}
    210211
    211 
    212212/** Destroy thread memory structure
    213213 *
     
    237237       
    238238        spinlock_lock(&threads_lock);
    239         list_remove(&t->threads_link);
     239        btree_remove(&threads_btree, (__native) t, NULL);
    240240        spinlock_unlock(&threads_lock);
    241241       
    242242        slab_free(thread_slab, t);
    243243}
    244 
    245244
    246245/** Create new thread
     
    312311        ipl = interrupts_disable();
    313312        spinlock_lock(&threads_lock);
    314         list_append(&t->threads_link, &threads_head);
     313        btree_insert(&threads_btree, (__native) t, (void *) t, NULL);
    315314        spinlock_unlock(&threads_lock);
    316315       
     
    326325        return t;
    327326}
    328 
    329327
    330328/** Make thread exiting
     
    364362}
    365363
    366 
    367364/** Thread usleep
    368365 *
     
    380377        (void) waitq_sleep_timeout(&wq, usec, SYNCH_NON_BLOCKING);
    381378}
    382 
    383379
    384380/** Register thread out-of-context invocation
     
    407403{
    408404        link_t *cur;
    409         thread_t *t;
    410405        ipl_t ipl;
    411406       
     
    414409        spinlock_lock(&threads_lock);
    415410
    416         for (cur=threads_head.next; cur!=&threads_head; cur=cur->next) {
    417                 t = list_get_instance(cur, thread_t, threads_link);
    418                 printf("%s: address=%P, tid=%d, state=%s, task=%P, code=%P, stack=%P, cpu=",
    419                         t->name, t, t->tid, thread_states[t->state], t->task, t->thread_code, t->kstack);
    420                 if (t->cpu)
    421                         printf("cpu%d ", t->cpu->id);
    422                 else
    423                         printf("none");
    424                 printf("\n");
     411        for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) {
     412                btree_node_t *node;
     413                int i;
     414
     415                node = list_get_instance(cur, btree_node_t, leaf_link);
     416                for (i = 0; i < node->keys; i++) {
     417                        thread_t *t;
     418               
     419                        t = (thread_t *) node->value[i];
     420                        printf("%s: address=%P, tid=%d, state=%s, task=%P, code=%P, stack=%P, cpu=",
     421                                t->name, t, t->tid, thread_states[t->state], t->task, t->thread_code, t->kstack);
     422                        if (t->cpu)
     423                                printf("cpu%d ", t->cpu->id);
     424                        else
     425                                printf("none");
     426                        printf("\n");
     427                }
    425428        }
    426429
    427430        spinlock_unlock(&threads_lock);
    428431        interrupts_restore(ipl);
     432}
     433
     434/** Check whether thread exists.
     435 *
     436 * Note that threads_lock must be already held and
     437 * interrupts must be already disabled.
     438 *
     439 * @param t Pointer to thread.
     440 *
     441 * @return True if thread t is known to the system, false otherwise.
     442 */
     443bool thread_exists(thread_t *t)
     444{
     445        btree_node_t *leaf;
     446       
     447        return btree_search(&threads_btree, (__native) t, &leaf) != NULL;
    429448}
    430449
  • generic/src/synch/waitq.c

    r203f4c3 r016acbe  
    7474
    7575        spinlock_lock(&threads_lock);
    76         if (!list_member(&t->threads_link, &threads_head))
     76        if (!thread_exists(t))
    7777                goto out;
    7878
     
    118118        ipl = interrupts_disable();
    119119        spinlock_lock(&threads_lock);
    120         if (!list_member(&t->threads_link, &threads_head))
     120        if (!thread_exists(t))
    121121                goto out;
    122122
Note: See TracChangeset for help on using the changeset viewer.