Changeset 016acbe in mainline
- Timestamp:
- 2006-04-09T14:58:42Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f6e755
- Parents:
- 203f4c3
- Location:
- generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/proc/thread.h
r203f4c3 r016acbe 39 39 #include <synch/rwlock.h> 40 40 #include <config.h> 41 #include <adt/btree.h> 41 42 #include <adt/list.h> 42 43 #include <mm/slab.h> … … 66 67 link_t wq_link; /**< Wait queue link. */ 67 68 link_t th_link; /**< Links to threads within containing task. */ 68 link_t threads_link; /**< Link to the list of all threads. */69 69 70 70 /** Lock protecting thread structure. … … 131 131 extern spinlock_t threads_lock; 132 132 133 extern link_t threads_head; /**< List of all threads in the system. */133 extern btree_t threads_btree; /**< B+tree containing all threads. */ 134 134 135 135 extern void thread_init(void); … … 144 144 extern void thread_print_list(void); 145 145 extern void thread_destroy(thread_t *t); 146 extern bool thread_exists(thread_t *t); 146 147 147 148 /* Fpu context slab cache */ -
generic/src/proc/thread.c
r203f4c3 r016acbe 42 42 #include <func.h> 43 43 #include <context.h> 44 #include <adt/btree.h> 44 45 #include <adt/list.h> 45 46 #include <typedefs.h> … … 59 60 char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */ 60 61 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. */ 63 SPINLOCK_INITIALIZE(threads_lock); 64 btree_t threads_btree; /**< B+tree of all threads. */ 63 65 64 66 SPINLOCK_INITIALIZE(tidlock); … … 70 72 #endif 71 73 72 73 74 /** Thread wrapper 74 75 * … … 105 106 link_initialize(&t->wq_link); 106 107 link_initialize(&t->th_link); 107 link_initialize(&t->threads_link);108 108 109 109 #ifdef ARCH_HAS_FPU … … 161 161 NULL, NULL, 0); 162 162 #endif 163 } 164 163 164 btree_create(&threads_btree); 165 } 165 166 166 167 /** Make thread ready … … 209 210 } 210 211 211 212 212 /** Destroy thread memory structure 213 213 * … … 237 237 238 238 spinlock_lock(&threads_lock); 239 list_remove(&t->threads_link);239 btree_remove(&threads_btree, (__native) t, NULL); 240 240 spinlock_unlock(&threads_lock); 241 241 242 242 slab_free(thread_slab, t); 243 243 } 244 245 244 246 245 /** Create new thread … … 312 311 ipl = interrupts_disable(); 313 312 spinlock_lock(&threads_lock); 314 list_append(&t->threads_link, &threads_head);313 btree_insert(&threads_btree, (__native) t, (void *) t, NULL); 315 314 spinlock_unlock(&threads_lock); 316 315 … … 326 325 return t; 327 326 } 328 329 327 330 328 /** Make thread exiting … … 364 362 } 365 363 366 367 364 /** Thread usleep 368 365 * … … 380 377 (void) waitq_sleep_timeout(&wq, usec, SYNCH_NON_BLOCKING); 381 378 } 382 383 379 384 380 /** Register thread out-of-context invocation … … 407 403 { 408 404 link_t *cur; 409 thread_t *t;410 405 ipl_t ipl; 411 406 … … 414 409 spinlock_lock(&threads_lock); 415 410 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 } 425 428 } 426 429 427 430 spinlock_unlock(&threads_lock); 428 431 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 */ 443 bool thread_exists(thread_t *t) 444 { 445 btree_node_t *leaf; 446 447 return btree_search(&threads_btree, (__native) t, &leaf) != NULL; 429 448 } 430 449 -
generic/src/synch/waitq.c
r203f4c3 r016acbe 74 74 75 75 spinlock_lock(&threads_lock); 76 if (! list_member(&t->threads_link, &threads_head))76 if (!thread_exists(t)) 77 77 goto out; 78 78 … … 118 118 ipl = interrupts_disable(); 119 119 spinlock_lock(&threads_lock); 120 if (! list_member(&t->threads_link, &threads_head))120 if (!thread_exists(t)) 121 121 goto out; 122 122
Note:
See TracChangeset
for help on using the changeset viewer.