Rev 2837 | Rev 2840 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2837 | Rev 2839 | ||
|---|---|---|---|
| Line 655... | Line 655... | ||
| 655 | } |
655 | } |
| 656 | 656 | ||
| 657 | klog_printf("kbox: finished"); |
657 | klog_printf("kbox: finished"); |
| 658 | } |
658 | } |
| 659 | 659 | ||
| - | 660 | ||
| 660 | /** |
661 | /** |
| 661 | * Connect phone to a task kernel-box specified by id. |
662 | * Connect phone to a task kernel-box specified by id. |
| 662 | * |
663 | * |
| 663 | * @return Phone id on success, or negative error code. |
664 | * @return Phone id on success, or negative error code. |
| 664 | */ |
665 | */ |
| 665 | int ipc_connect_kbox(task_id_t taskid) |
666 | int ipc_connect_kbox(task_id_t taskid) |
| 666 | { |
667 | { |
| 667 | int newphid; |
668 | int newphid; |
| 668 | task_t *ta; |
669 | task_t *ta; |
| - | 670 | thread_t *kb_thread; |
|
| - | 671 | int rc; |
|
| - | 672 | ipl_t ipl; |
|
| 669 | 673 | ||
| 670 | newphid = phone_alloc(); |
674 | newphid = phone_alloc(); |
| 671 | if (newphid < 0) |
675 | if (newphid < 0) |
| 672 | return ELIMIT; |
676 | return ELIMIT; |
| 673 | 677 | ||
| - | 678 | ipl = interrupts_disable(); |
|
| 674 | spinlock_lock(&tasks_lock); |
679 | spinlock_lock(&tasks_lock); |
| - | 680 | ||
| 675 | ta = task_find_by_id(taskid); |
681 | ta = task_find_by_id(taskid); |
| 676 | if (ta == NULL) { |
682 | if (ta == NULL) { |
| 677 | spinlock_unlock(&tasks_lock); |
683 | spinlock_unlock(&tasks_lock); |
| 678 | return ENOENT; |
684 | return ENOENT; |
| 679 | } |
685 | } |
| 680 | 686 | ||
| 681 | spinlock_lock(&ta->lock); |
687 | spinlock_lock(&ta->lock); |
| 682 | spinlock_unlock(&tasks_lock); |
688 | spinlock_unlock(&tasks_lock); |
| 683 | 689 | ||
| 684 | ipc_phone_connect(&TASK->phones[newphid], &ta->kernel_box); |
690 | ipc_phone_connect(&TASK->phones[newphid], &ta->kernel_box); |
| 685 | spinlock_unlock(&ta->lock); |
- | |
| 686 | 691 | ||
| 687 | /* FIXME: locking! */ |
692 | if (ta->kb_thread_at_hand == false) { |
| 688 | if (ta->kb_thread == NULL) { |
693 | ta->kb_thread_at_hand = true; |
| - | 694 | spinlock_unlock(&ta->lock); |
|
| - | 695 | interrupts_restore(ipl); |
|
| - | 696 | ||
| 689 | ta->kb_thread = thread_create(kbox_thread_proc, |
697 | kb_thread = thread_create(kbox_thread_proc, |
| 690 | NULL, ta, 0, "kbox", false); |
698 | NULL, ta, THREAD_FLAG_NOATTACH, "kbox", false); |
| 691 | if (!ta->kb_thread) |
699 | if (!kb_thread) |
| 692 | return ENOMEM; |
700 | return ENOMEM; |
| 693 | 701 | ||
| - | 702 | rc = thread_attach_by_id(kb_thread, taskid); |
|
| - | 703 | ||
| - | 704 | if (rc == EOK) { |
|
| - | 705 | ipl = interrupts_disable(); |
|
| - | 706 | spinlock_lock(&ta->lock); |
|
| - | 707 | ta->kb_thread = kb_thread; |
|
| - | 708 | spinlock_unlock(&ta->lock); |
|
| - | 709 | interrupts_restore(ipl); |
|
| - | 710 | ||
| 694 | thread_detach(ta->kb_thread); |
711 | thread_detach(kb_thread); |
| 695 | thread_ready(ta->kb_thread); |
712 | thread_ready(kb_thread); |
| - | 713 | } else { |
|
| - | 714 | /* Return the allocated thread struct */ |
|
| - | 715 | thread_unattached_free(kb_thread); |
|
| - | 716 | } |
|
| - | 717 | } else { |
|
| - | 718 | spinlock_unlock(&ta->lock); |
|
| - | 719 | interrupts_restore(ipl); |
|
| 696 | } |
720 | } |
| 697 | 721 | ||
| 698 | return newphid; |
722 | return newphid; |
| 699 | } |
723 | } |
| 700 | 724 | ||