Changeset 31696b4f in mainline for kernel/generic/src/ipc/kbox.c


Ignore:
Timestamp:
2008-11-23T10:59:21Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
50e5b25
Parents:
0aa1665
Message:

Move stuff related to kbox to a separate struct.

File:
1 edited

Legend:

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

    r0aa1665 r31696b4f  
    4949        bool have_kb_thread;
    5050
    51         /* Only hold kb_cleanup_lock while setting kb_finished - this is enough */
    52         mutex_lock(&TASK->kb_cleanup_lock);
    53         TASK->kb_finished = true;
    54         mutex_unlock(&TASK->kb_cleanup_lock);
    55 
    56         have_kb_thread = (TASK->kb_thread != NULL);
    57 
    58         /* From now on nobody will try to connect phones or attach kbox threads */
     51        /*
     52         * Only hold kb.cleanup_lock while setting kb.finished -
     53         * this is enough.
     54         */
     55        mutex_lock(&TASK->kb.cleanup_lock);
     56        TASK->kb.finished = true;
     57        mutex_unlock(&TASK->kb.cleanup_lock);
     58
     59        have_kb_thread = (TASK->kb.thread != NULL);
     60
     61        /*
     62         * From now on nobody will try to connect phones or attach
     63         * kbox threads
     64         */
    5965
    6066        /*
     
    6470         * wake up and terminate.
    6571         */
    66         ipc_answerbox_slam_phones(&TASK->kernel_box, have_kb_thread);
     72        ipc_answerbox_slam_phones(&TASK->kb.box, have_kb_thread);
    6773
    6874        /*
     
    7884       
    7985        if (have_kb_thread) {
    80                 LOG("join kb_thread..\n");
    81                 thread_join(TASK->kb_thread);
    82                 thread_detach(TASK->kb_thread);
     86                LOG("join kb.thread..\n");
     87                thread_join(TASK->kb.thread);
     88                thread_detach(TASK->kb.thread);
    8389                LOG("join done\n");
    84                 TASK->kb_thread = NULL;
    85         }
    86 
    87         /* Answer all messages in 'calls' and 'dispatched_calls' queues */
    88         spinlock_lock(&TASK->kernel_box.lock);
    89         ipc_cleanup_call_list(&TASK->kernel_box.dispatched_calls);
    90         ipc_cleanup_call_list(&TASK->kernel_box.calls);
    91         spinlock_unlock(&TASK->kernel_box.lock);
     90                TASK->kb.thread = NULL;
     91        }
     92
     93        /* Answer all messages in 'calls' and 'dispatched_calls' queues. */
     94        spinlock_lock(&TASK->kb.box.lock);
     95        ipc_cleanup_call_list(&TASK->kb.box.dispatched_calls);
     96        ipc_cleanup_call_list(&TASK->kb.box.calls);
     97        spinlock_unlock(&TASK->kb.box.lock);
    9298}
    9399
     
    106112        /* Was it our debugger, who hung up? */
    107113        if (call->sender == TASK->udebug.debugger) {
    108                 /* Terminate debugging session (if any) */
     114                /* Terminate debugging session (if any). */
    109115                LOG("kbox: terminate debug session\n");
    110116                ipl = interrupts_disable();
     
    119125        LOG("kbox: continue with hangup message\n");
    120126        IPC_SET_RETVAL(call->data, 0);
    121         ipc_answer(&TASK->kernel_box, call);
     127        ipc_answer(&TASK->kb.box, call);
    122128
    123129        ipl = interrupts_disable();
     
    131137
    132138                /* Only detach kbox thread unless already terminating. */
    133                 mutex_lock(&TASK->kb_cleanup_lock);
    134                 if (&TASK->kb_finished == false) {
     139                mutex_lock(&TASK->kb.cleanup_lock);
     140                if (&TASK->kb.finished == false) {
    135141                        /* Detach kbox thread so it gets freed from memory. */
    136                         thread_detach(TASK->kb_thread);
    137                         TASK->kb_thread = NULL;
     142                        thread_detach(TASK->kb.thread);
     143                        TASK->kb.thread = NULL;
    138144                }
    139                 mutex_unlock(&TASK->kb_cleanup_lock);
     145                mutex_unlock(&TASK->kb.cleanup_lock);
    140146
    141147                LOG("phone list is empty\n");
     
    167173
    168174        while (!done) {
    169                 call = ipc_wait_for_call(&TASK->kernel_box, SYNCH_NO_TIMEOUT,
     175                call = ipc_wait_for_call(&TASK->kb.box, SYNCH_NO_TIMEOUT,
    170176                        SYNCH_FLAGS_NONE);
    171177
     
    202208 * Connect phone to a task kernel-box specified by id.
    203209 *
    204  * Note that this is not completely atomic. For optimisation reasons,
    205  * The task might start cleaning up kbox after the phone has been connected
    206  * and before a kbox thread has been created. This must be taken into account
    207  * in the cleanup code.
     210 * Note that this is not completely atomic. For optimisation reasons, the task
     211 * might start cleaning up kbox after the phone has been connected and before
     212 * a kbox thread has been created. This must be taken into account in the
     213 * cleanup code.
    208214 *
    209215 * @return              Phone id on success, or negative error code.
     
    231237        interrupts_restore(ipl);
    232238
    233         mutex_lock(&ta->kb_cleanup_lock);
     239        mutex_lock(&ta->kb.cleanup_lock);
    234240
    235241        if (atomic_predec(&ta->refcount) == 0) {
    236                 mutex_unlock(&ta->kb_cleanup_lock);
     242                mutex_unlock(&ta->kb.cleanup_lock);
    237243                task_destroy(ta);
    238244                return ENOENT;
    239245        }
    240246
    241         if (ta->kb_finished != false) {
    242                 mutex_unlock(&ta->kb_cleanup_lock);
     247        if (ta->kb.finished != false) {
     248                mutex_unlock(&ta->kb.cleanup_lock);
    243249                return EINVAL;
    244250        }
     
    246252        newphid = phone_alloc();
    247253        if (newphid < 0) {
    248                 mutex_unlock(&ta->kb_cleanup_lock);
     254                mutex_unlock(&ta->kb.cleanup_lock);
    249255                return ELIMIT;
    250256        }
    251257
    252258        /* Connect the newly allocated phone to the kbox */
    253         ipc_phone_connect(&TASK->phones[newphid], &ta->kernel_box);
    254 
    255         if (ta->kb_thread != NULL) {
    256                 mutex_unlock(&ta->kb_cleanup_lock);
     259        ipc_phone_connect(&TASK->phones[newphid], &ta->kb.box);
     260
     261        if (ta->kb.thread != NULL) {
     262                mutex_unlock(&ta->kb.cleanup_lock);
    257263                return newphid;
    258264        }
    259265
    260266        /* Create a kbox thread */
    261         kb_thread = thread_create(kbox_thread_proc, NULL, ta, 0, "kbox", false);
     267        kb_thread = thread_create(kbox_thread_proc, NULL, ta, 0,
     268            "kbox", false);
    262269        if (!kb_thread) {
    263                 mutex_unlock(&ta->kb_cleanup_lock);
     270                mutex_unlock(&ta->kb.cleanup_lock);
    264271                return ENOMEM;
    265272        }
    266273
    267         ta->kb_thread = kb_thread;
     274        ta->kb.thread = kb_thread;
    268275        thread_ready(kb_thread);
    269276
    270         mutex_unlock(&ta->kb_cleanup_lock);
     277        mutex_unlock(&ta->kb.cleanup_lock);
    271278
    272279        return newphid;
Note: See TracChangeset for help on using the changeset viewer.