Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/kbox.c

    rfafb8e5 r07d4271  
    9090                LOG("Join kb.thread.");
    9191                thread_join(TASK->kb.thread);
    92                 thread_detach(TASK->kb.thread);
    9392                LOG("...join done.");
    9493                TASK->kb.thread = NULL;
     
    136135                /* Only detach kbox thread unless already terminating. */
    137136                if (TASK->kb.finished == false) {
    138                         /* Detach kbox thread so it gets freed from memory. */
    139                         thread_detach(TASK->kb.thread);
     137                        /* Release kbox thread so it gets freed from memory. */
     138                        thread_put(TASK->kb.thread);
    140139                        TASK->kb.thread = NULL;
    141140                }
     
    201200/** Connect phone to a task kernel-box specified by id.
    202201 *
    203  * Note that this is not completely atomic. For optimisation reasons, the task
    204  * might start cleaning up kbox after the phone has been connected and before
    205  * a kbox thread has been created. This must be taken into account in the
    206  * cleanup code.
    207  *
    208202 * @param[out] out_phone  Phone capability handle on success.
    209203 * @return Error code.
     
    212206errno_t ipc_connect_kbox(task_id_t taskid, cap_phone_handle_t *out_phone)
    213207{
    214         irq_spinlock_lock(&tasks_lock, true);
    215 
    216208        task_t *task = task_find_by_id(taskid);
    217         if (task == NULL) {
    218                 irq_spinlock_unlock(&tasks_lock, true);
     209        if (!task)
    219210                return ENOENT;
    220         }
    221 
    222         atomic_inc(&task->refcount);
    223 
    224         irq_spinlock_unlock(&tasks_lock, true);
    225211
    226212        mutex_lock(&task->kb.cleanup_lock);
    227 
    228         if (atomic_predec(&task->refcount) == 0) {
    229                 mutex_unlock(&task->kb.cleanup_lock);
    230                 task_destroy(task);
    231                 return ENOENT;
    232         }
    233213
    234214        if (task->kb.finished) {
    235215                mutex_unlock(&task->kb.cleanup_lock);
     216                task_release(task);
    236217                return EINVAL;
    237218        }
     
    244225                if (!kb_thread) {
    245226                        mutex_unlock(&task->kb.cleanup_lock);
     227                        task_release(task);
    246228                        return ENOMEM;
    247229                }
    248230
    249231                task->kb.thread = kb_thread;
    250                 thread_ready(kb_thread);
     232                thread_start(kb_thread);
    251233        }
    252234
     
    256238        if (rc != EOK) {
    257239                mutex_unlock(&task->kb.cleanup_lock);
     240                task_release(task);
    258241                return rc;
    259242        }
     
    266249
    267250        mutex_unlock(&task->kb.cleanup_lock);
     251        task_release(task);
    268252        *out_phone = phone_handle;
    269253        return EOK;
Note: See TracChangeset for help on using the changeset viewer.