Changeset 266294a9 in mainline for generic/src/proc/thread.c
- Timestamp:
- 2006-02-05T17:01:03Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5c9a08b
- Parents:
- 9b9e385
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/proc/thread.c
r9b9e385 r266294a9 53 53 #include <memstr.h> 54 54 #include <print.h> 55 #include <mm/slab.h> 56 #include <debug.h> 55 57 56 58 char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */ … … 61 63 SPINLOCK_INITIALIZE(tidlock); 62 64 __u32 last_tid = 0; 65 66 static slab_cache_t *thread_slab; 63 67 64 68 … … 88 92 } 89 93 94 /** Initialization and allocation for thread_t structure */ 95 static int thr_constructor(void *obj, int kmflags) 96 { 97 thread_t *t = (thread_t *)obj; 98 99 spinlock_initialize(&t->lock, "thread_t_lock"); 100 link_initialize(&t->rq_link); 101 link_initialize(&t->wq_link); 102 link_initialize(&t->th_link); 103 link_initialize(&t->threads_link); 104 105 t->kstack = (__u8 *)frame_alloc(ONE_FRAME, FRAME_KA | kmflags); 106 if (!t->kstack) 107 return -1; 108 109 return 0; 110 } 111 112 /** Destruction of thread_t object */ 113 static int thr_destructor(void *obj) 114 { 115 thread_t *t = (thread_t *)obj; 116 117 frame_free((__address) t->kstack); 118 return 1; /* One page freed */ 119 } 90 120 91 121 /** Initialize threads … … 98 128 THREAD = NULL; 99 129 atomic_set(&nrdy,0); 130 thread_slab = slab_cache_create("thread_slab", 131 sizeof(thread_t),0, 132 thr_constructor, thr_destructor, 0); 100 133 } 101 134 … … 144 177 145 178 179 /** Destroy thread memory structure 180 * 181 * Detach thread from all queues, cpus etc. and destroy it. 182 * 183 * Assume thread->lock is held!! 184 */ 185 void thread_destroy(thread_t *t) 186 { 187 ASSERT(t->state == Exiting); 188 ASSERT(t->task); 189 ASSERT(t->cpu); 190 191 spinlock_lock(&t->cpu->lock); 192 if(t->cpu->fpu_owner==t) 193 t->cpu->fpu_owner=NULL; 194 spinlock_unlock(&t->cpu->lock); 195 196 if (t->ustack) 197 frame_free((__address) t->ustack); 198 199 /* 200 * Detach from the containing task. 201 */ 202 spinlock_lock(&t->task->lock); 203 list_remove(&t->th_link); 204 spinlock_unlock(&t->task->lock); 205 206 spinlock_unlock(&t->lock); 207 208 spinlock_lock(&threads_lock); 209 list_remove(&t->threads_link); 210 spinlock_unlock(&threads_lock); 211 212 slab_free(thread_slab, t); 213 } 214 215 146 216 /** Create new thread 147 217 * … … 159 229 { 160 230 thread_t *t; 161 __address frame_ ks, frame_us = NULL;162 163 t = (thread_t *) malloc(sizeof(thread_t));231 __address frame_us = NULL; 232 233 t = (thread_t *) slab_alloc(thread_slab, 0); 164 234 if (t) { 165 235 ipl_t ipl; 166 236 167 spinlock_initialize(&t->lock, "thread_t_lock");168 169 frame_ks = frame_alloc(ONE_FRAME, FRAME_KA);170 237 if (THREAD_USER_STACK & flags) { 171 238 frame_us = frame_alloc(ONE_FRAME, FRAME_KA); 172 239 } 240 241 /* Not needed, but good for debugging */ 242 memsetb((__address)t->kstack, THREAD_STACK_SIZE, 0); 173 243 174 244 ipl = interrupts_disable(); … … 178 248 interrupts_restore(ipl); 179 249 180 memsetb(frame_ks, THREAD_STACK_SIZE, 0);181 link_initialize(&t->rq_link);182 link_initialize(&t->wq_link);183 link_initialize(&t->th_link);184 link_initialize(&t->threads_link);185 t->kstack = (__u8 *) frame_ks;186 250 t->ustack = (__u8 *) frame_us; 187 251 … … 219 283 * Register this thread in the system-wide list. 220 284 */ 221 ipl = interrupts_disable(); 285 ipl = interrupts_disable(); 222 286 spinlock_lock(&threads_lock); 223 287 list_append(&t->threads_link, &threads_head);
Note:
See TracChangeset
for help on using the changeset viewer.