Changes in kernel/generic/src/proc/task.c [07d4271:5a5269d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
r07d4271 r5a5269d 158 158 return rc; 159 159 160 atomic_store(&task->refcount, 0); 160 161 atomic_store(&task->lifecount, 0); 161 162 … … 200 201 if (!task) 201 202 return NULL; 202 203 refcount_init(&task->refcount);204 203 205 204 task_create_arch(task); … … 225 224 226 225 task->answerbox.active = true; 227 228 task->debug_sections = NULL;229 226 230 227 #ifdef CONFIG_UDEBUG … … 269 266 * 270 267 */ 271 staticvoid task_destroy(task_t *task)268 void task_destroy(task_t *task) 272 269 { 273 270 /* … … 300 297 void task_hold(task_t *task) 301 298 { 302 refcount_up(&task->refcount);299 atomic_inc(&task->refcount); 303 300 } 304 301 … … 312 309 void task_release(task_t *task) 313 310 { 314 if ( refcount_down(&task->refcount))311 if ((atomic_predec(&task->refcount)) == 0) 315 312 task_destroy(task); 316 313 } … … 388 385 irq_spinlock_lock(&tasks_lock, true); 389 386 irq_spinlock_lock(&TASK->lock, false); 387 irq_spinlock_lock(&threads_lock, false); 390 388 391 389 /* Set task name */ 392 390 str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf); 393 391 392 irq_spinlock_unlock(&threads_lock, false); 394 393 irq_spinlock_unlock(&TASK->lock, false); 395 394 irq_spinlock_unlock(&tasks_lock, true); … … 417 416 /** Find task structure corresponding to task ID. 418 417 * 418 * The tasks_lock must be already held by the caller of this function and 419 * interrupts must be disabled. 420 * 419 421 * @param id Task ID. 420 422 * 421 * @return Task referenceor NULL if there is no such task ID.423 * @return Task structure address or NULL if there is no such task ID. 422 424 * 423 425 */ 424 426 task_t *task_find_by_id(task_id_t id) 425 427 { 426 task_t *task = NULL; 427 428 irq_spinlock_lock(&tasks_lock, true); 428 assert(interrupts_disabled()); 429 assert(irq_spinlock_locked(&tasks_lock)); 429 430 430 431 odlink_t *odlink = odict_find_eq(&tasks, &id, NULL); 431 if (odlink != NULL) { 432 task = odict_get_instance(odlink, task_t, ltasks); 433 434 /* 435 * The directory of tasks can't hold a reference, since that would 436 * prevent task from ever being destroyed. That means we have to 437 * check for the case where the task is already being destroyed, but 438 * not yet removed from the directory. 439 */ 440 if (!refcount_try_up(&task->refcount)) 441 task = NULL; 442 } 443 444 irq_spinlock_unlock(&tasks_lock, true); 445 446 return task; 432 if (odlink != NULL) 433 return odict_get_instance(odlink, task_t, ltasks); 434 435 return NULL; 447 436 } 448 437 … … 517 506 /* Current values of threads */ 518 507 list_foreach(task->threads, th_link, thread_t, thread) { 508 irq_spinlock_lock(&thread->lock, false); 509 519 510 /* Process only counted threads */ 520 511 if (!thread->uncounted) { … … 524 515 } 525 516 526 uret += atomic_time_read(&thread->ucycles);527 kret += atomic_time_read(&thread->kcycles);517 uret += thread->ucycles; 518 kret += thread->kcycles; 528 519 } 520 521 irq_spinlock_unlock(&thread->lock, false); 529 522 } 530 523 … … 535 528 static void task_kill_internal(task_t *task) 536 529 { 537 irq_spinlock_lock(&task->lock, true); 530 irq_spinlock_lock(&task->lock, false); 531 irq_spinlock_lock(&threads_lock, false); 538 532 539 533 /* … … 542 536 543 537 list_foreach(task->threads, th_link, thread_t, thread) { 544 thread_interrupt(thread); 538 bool sleeping = false; 539 540 irq_spinlock_lock(&thread->lock, false); 541 542 thread->interrupted = true; 543 if (thread->state == Sleeping) 544 sleeping = true; 545 546 irq_spinlock_unlock(&thread->lock, false); 547 548 if (sleeping) 549 waitq_interrupt_sleep(thread); 545 550 } 546 551 547 irq_spinlock_unlock(&task->lock, true); 552 irq_spinlock_unlock(&threads_lock, false); 553 irq_spinlock_unlock(&task->lock, false); 548 554 } 549 555 … … 563 569 return EPERM; 564 570 571 irq_spinlock_lock(&tasks_lock, true); 572 565 573 task_t *task = task_find_by_id(id); 566 if (!task) 574 if (!task) { 575 irq_spinlock_unlock(&tasks_lock, true); 567 576 return ENOENT; 577 } 568 578 569 579 task_kill_internal(task); 570 task_release(task); 580 irq_spinlock_unlock(&tasks_lock, true); 581 571 582 return EOK; 572 583 } … … 598 609 } 599 610 611 irq_spinlock_lock(&tasks_lock, true); 600 612 task_kill_internal(TASK); 613 irq_spinlock_unlock(&tasks_lock, true); 614 601 615 thread_exit(); 602 616 } … … 627 641 if (additional) 628 642 printf("%-8" PRIu64 " %9zu", task->taskid, 629 atomic_load(&task-> lifecount));643 atomic_load(&task->refcount)); 630 644 else 631 645 printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %10p %10p" … … 639 653 printf("%-8" PRIu64 " %9" PRIu64 "%c %9" PRIu64 "%c " 640 654 "%9zu\n", task->taskid, ucycles, usuffix, kcycles, 641 ksuffix, atomic_load(&task-> lifecount));655 ksuffix, atomic_load(&task->refcount)); 642 656 else 643 657 printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %18p %18p\n",
Note:
See TracChangeset
for help on using the changeset viewer.