657,6 → 657,7 |
klog_printf("kbox: finished"); |
} |
|
|
/** |
* Connect phone to a task kernel-box specified by id. |
* |
666,12 → 667,17 |
{ |
int newphid; |
task_t *ta; |
thread_t *kb_thread; |
int rc; |
ipl_t ipl; |
|
newphid = phone_alloc(); |
if (newphid < 0) |
return ELIMIT; |
|
ipl = interrupts_disable(); |
spinlock_lock(&tasks_lock); |
|
ta = task_find_by_id(taskid); |
if (ta == NULL) { |
spinlock_unlock(&tasks_lock); |
682,17 → 688,35 |
spinlock_unlock(&tasks_lock); |
|
ipc_phone_connect(&TASK->phones[newphid], &ta->kernel_box); |
spinlock_unlock(&ta->lock); |
|
/* FIXME: locking! */ |
if (ta->kb_thread == NULL) { |
ta->kb_thread = thread_create(kbox_thread_proc, |
NULL, ta, 0, "kbox", false); |
if (!ta->kb_thread) |
if (ta->kb_thread_at_hand == false) { |
ta->kb_thread_at_hand = true; |
spinlock_unlock(&ta->lock); |
interrupts_restore(ipl); |
|
kb_thread = thread_create(kbox_thread_proc, |
NULL, ta, THREAD_FLAG_NOATTACH, "kbox", false); |
if (!kb_thread) |
return ENOMEM; |
|
thread_detach(ta->kb_thread); |
thread_ready(ta->kb_thread); |
rc = thread_attach_by_id(kb_thread, taskid); |
|
if (rc == EOK) { |
ipl = interrupts_disable(); |
spinlock_lock(&ta->lock); |
ta->kb_thread = kb_thread; |
spinlock_unlock(&ta->lock); |
interrupts_restore(ipl); |
|
thread_detach(kb_thread); |
thread_ready(kb_thread); |
} else { |
/* Return the allocated thread struct */ |
thread_unattached_free(kb_thread); |
} |
} else { |
spinlock_unlock(&ta->lock); |
interrupts_restore(ipl); |
} |
|
return newphid; |