Changeset bb252ca in mainline for kernel/generic/src
- Timestamp:
- 2010-05-02T20:58:27Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4872160
- Parents:
- 4ce914d4 (diff), 1624aae (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- kernel/generic/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/as.c
r4ce914d4 rbb252ca 1 1 /* 2 * Copyright (c) 20 01-2006Jakub Jermar2 * Copyright (c) 2010 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 152 152 * reference count never drops to zero. 153 153 */ 154 a tomic_set(&AS_KERNEL->refcount, 1);154 as_hold(AS_KERNEL); 155 155 } 156 156 … … 200 200 DEADLOCK_PROBE_INIT(p_asidlock); 201 201 202 ASSERT(as != AS); 202 203 ASSERT(atomic_get(&as->refcount) == 0); 203 204 204 205 /* 205 * Since there is no reference to this a rea,206 * it is safe not tolock its mutex.206 * Since there is no reference to this address space, it is safe not to 207 * lock its mutex. 207 208 */ 208 209 … … 225 226 preemption_enable(); /* Interrupts disabled, enable preemption */ 226 227 if (as->asid != ASID_INVALID && as != AS_KERNEL) { 227 if (as != AS && as->cpu_refcount == 0)228 if (as->cpu_refcount == 0) 228 229 list_remove(&as->inactive_as_with_asid_link); 229 230 asid_put(as->asid); … … 258 259 259 260 slab_free(as_slab, as); 261 } 262 263 /** Hold a reference to an address space. 264 * 265 * Holding a reference to an address space prevents destruction of that address 266 * space. 267 * 268 * @param a Address space to be held. 269 */ 270 void as_hold(as_t *as) 271 { 272 atomic_inc(&as->refcount); 273 } 274 275 /** Release a reference to an address space. 276 * 277 * The last one to release a reference to an address space destroys the address 278 * space. 279 * 280 * @param a Address space to be released. 281 */ 282 void as_release(as_t *as) 283 { 284 if (atomic_predec(&as->refcount) == 0) 285 as_destroy(as); 260 286 } 261 287 -
kernel/generic/src/proc/scheduler.c
r4ce914d4 rbb252ca 1 1 /* 2 * Copyright (c) 20 01-2007Jakub Jermar2 * Copyright (c) 2010 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 382 382 int priority; 383 383 DEADLOCK_PROBE_INIT(p_joinwq); 384 task_t *old_task = TASK; 385 as_t *old_as = AS; 384 386 385 387 ASSERT(CPU != NULL); 386 388 389 /* 390 * Hold the current task and the address space to prevent their 391 * possible destruction should thread_destroy() be called on this or any 392 * other processor while the scheduler is still using them. 393 */ 394 if (old_task) 395 task_hold(old_task); 396 if (old_as) 397 as_hold(old_as); 398 387 399 if (THREAD) { 388 400 /* must be run after the switch to scheduler stack */ … … 476 488 */ 477 489 if (TASK != THREAD->task) { 478 as_t *as1 = NULL; 479 as_t *as2; 480 481 if (TASK) { 482 spinlock_lock(&TASK->lock); 483 as1 = TASK->as; 484 spinlock_unlock(&TASK->lock); 485 } 486 487 spinlock_lock(&THREAD->task->lock); 488 as2 = THREAD->task->as; 489 spinlock_unlock(&THREAD->task->lock); 490 as_t *new_as = THREAD->task->as; 490 491 491 492 /* … … 493 494 * space. 494 495 */ 495 if ( as1 != as2) {496 if (old_as != new_as) { 496 497 /* 497 498 * Both tasks and address spaces are different. 498 499 * Replace the old one with the new one. 499 500 */ 500 as_switch( as1, as2);501 as_switch(old_as, new_as); 501 502 } 503 502 504 TASK = THREAD->task; 503 505 before_task_runs(); 504 506 } 505 507 508 if (old_task) 509 task_release(old_task); 510 if (old_as) 511 as_release(old_as); 512 506 513 spinlock_lock(&THREAD->lock); 507 514 THREAD->state = Running; -
kernel/generic/src/proc/task.c
r4ce914d4 rbb252ca 1 1 /* 2 * Copyright (c) 20 01-2004Jakub Jermar2 * Copyright (c) 2010 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 210 210 btree_create(&ta->futexes); 211 211 212 /* 213 * Get a reference to the address space. 214 */ 215 as_hold(ta->as); 216 212 217 ipl = interrupts_disable(); 213 atomic_inc(&as->refcount);214 218 spinlock_lock(&tasks_lock); 215 219 ta->taskid = ++task_counter; … … 250 254 * Drop our reference to the address space. 251 255 */ 252 if (atomic_predec(&t->as->refcount) == 0) 253 as_destroy(t->as); 256 as_release(t->as); 254 257 255 258 slab_free(task_slab, t); 256 TASK = NULL; 259 } 260 261 /** Hold a reference to a task. 262 * 263 * Holding a reference to a task prevents destruction of that task. 264 * 265 * @param t Task to be held. 266 */ 267 void task_hold(task_t *t) 268 { 269 atomic_inc(&t->refcount); 270 } 271 272 /** Release a reference to a task. 273 * 274 * The last one to release a reference to a task destroys the task. 275 * 276 * @param t Task to be released. 277 */ 278 void task_release(task_t *t) 279 { 280 if ((atomic_predec(&t->refcount)) == 0) 281 task_destroy(t); 257 282 } 258 283 -
kernel/generic/src/proc/thread.c
r4ce914d4 rbb252ca 1 1 /* 2 * Copyright (c) 20 01-2004Jakub Jermar2 * Copyright (c) 2010 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 409 409 410 410 /* 411 * t is guaranteed to be the very last thread of its task. 412 * It is safe to destroy the task. 411 * Drop the reference to the containing task. 413 412 */ 414 if (atomic_predec(&t->task->refcount) == 0) 415 task_destroy(t->task); 413 task_release(t->task); 416 414 417 415 slab_free(thread_slab, t); … … 436 434 spinlock_lock(&task->lock); 437 435 438 atomic_inc(&task->refcount); 436 /* Hold a reference to the task. */ 437 task_hold(task); 439 438 440 439 /* Must not count kbox thread into lifecount */
Note:
See TracChangeset
for help on using the changeset viewer.