Changeset 31696b4f in mainline


Ignore:
Timestamp:
2008-11-23T10:59:21Z (15 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.

Location:
kernel/generic
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/kbox.h

    r0aa1665 r31696b4f  
    3838#include <typedefs.h>
    3939
     40/** Kernel answerbox structure. */
     41typedef struct kbox {
     42        /** The answerbox itself. */
     43        answerbox_t box;
     44        /** Thread used to service the answerbox. */
     45        struct thread *thread;
     46        /** Kbox thread creation vs. begin of cleanup mutual exclusion. */
     47        mutex_t cleanup_lock;
     48        /** True if cleanup of kbox has already started. */
     49        bool finished;
     50} kbox_t;
     51
    4052extern int ipc_connect_kbox(task_id_t);
    4153extern void ipc_kbox_cleanup(void);
  • kernel/generic/include/proc/task.h

    r0aa1665 r31696b4f  
    5454#include <proc/scheduler.h>
    5555#include <udebug/udebug.h>
     56#include <ipc/kbox.h>
    5657
    5758#define TASK_NAME_BUFLEN        20
     
    99100
    100101#ifdef CONFIG_UDEBUG
    101         /** Debugging stuff */
     102        /** Debugging stuff. */
    102103        udebug_task_t udebug;
    103104
    104         /** Kernel answerbox */
    105         answerbox_t kernel_box;
    106         /** Thread used to service kernel answerbox */
    107         struct thread *kb_thread;
    108         /** Kbox thread creation vs. begin of cleanup mutual exclusion */
    109         mutex_t kb_cleanup_lock;
    110         /** True if cleanup of kbox has already started */
    111         bool kb_finished;
     105        /** Kernel answerbox. */
     106        kbox_t kb;
    112107#endif
    113        
     108
    114109        /** Architecture specific task data. */
    115110        task_arch_t arch;
  • 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;
  • kernel/generic/src/proc/task.c

    r0aa1665 r31696b4f  
    165165
    166166        /* Init kbox stuff */
    167         ipc_answerbox_init(&ta->kernel_box, ta);
    168         ta->kb_thread = NULL;
    169         mutex_initialize(&ta->kb_cleanup_lock, MUTEX_PASSIVE);
    170         ta->kb_finished = false;
     167        ipc_answerbox_init(&ta->kb.box, ta);
     168        ta->kb.thread = NULL;
     169        mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
     170        ta->kb.finished = false;
    171171#endif
    172172
  • kernel/generic/src/udebug/udebug_ipc.c

    r0aa1665 r31696b4f  
    7474        if (rc < 0) {
    7575                IPC_SET_RETVAL(call->data, rc);
    76                 ipc_answer(&TASK->kernel_box, call);
     76                ipc_answer(&TASK->kb.box, call);
    7777                return;
    7878        }
     
    8484        if (rc != 0) {
    8585                IPC_SET_RETVAL(call->data, 0);
    86                 ipc_answer(&TASK->kernel_box, call);
     86                ipc_answer(&TASK->kb.box, call);
    8787        }
    8888}
     
    100100
    101101        IPC_SET_RETVAL(call->data, rc);
    102         ipc_answer(&TASK->kernel_box, call);
     102        ipc_answer(&TASK->kb.box, call);
    103103}
    104104
     
    117117
    118118        IPC_SET_RETVAL(call->data, rc);
    119         ipc_answer(&TASK->kernel_box, call);
     119        ipc_answer(&TASK->kb.box, call);
    120120}
    121121
     
    136136        if (rc < 0) {
    137137                IPC_SET_RETVAL(call->data, rc);
    138                 ipc_answer(&TASK->kernel_box, call);
     138                ipc_answer(&TASK->kb.box, call);
    139139                return;
    140140        }
     
    155155        rc = udebug_stop(t, call);
    156156        IPC_SET_RETVAL(call->data, rc);
    157         ipc_answer(&TASK->kernel_box, call);
     157        ipc_answer(&TASK->kb.box, call);
    158158}
    159159
     
    183183        if (rc < 0) {
    184184                IPC_SET_RETVAL(call->data, rc);
    185                 ipc_answer(&TASK->kernel_box, call);
     185                ipc_answer(&TASK->kb.box, call);
    186186                return;
    187187        }
     
    210210        call->buffer = buffer;
    211211
    212         ipc_answer(&TASK->kernel_box, call);
     212        ipc_answer(&TASK->kb.box, call);
    213213}
    214214
     
    230230        if (rc != EOK) {
    231231                IPC_SET_RETVAL(call->data, rc);
    232                 ipc_answer(&TASK->kernel_box, call);
     232                ipc_answer(&TASK->kb.box, call);
    233233                return;
    234234        }
     
    248248        call->buffer = buffer;
    249249
    250         ipc_answer(&TASK->kernel_box, call);
     250        ipc_answer(&TASK->kb.box, call);
    251251}
    252252
     
    271271        if (rc < 0) {
    272272                IPC_SET_RETVAL(call->data, rc);
    273                 ipc_answer(&TASK->kernel_box, call);
     273                ipc_answer(&TASK->kb.box, call);
    274274                return;
    275275        }
     
    283283        call->buffer = buffer;
    284284
    285         ipc_answer(&TASK->kernel_box, call);
     285        ipc_answer(&TASK->kb.box, call);
    286286}
    287287
     
    307307                if (TASK->udebug.debugger != call->sender) {
    308308                        IPC_SET_RETVAL(call->data, EINVAL);
    309                         ipc_answer(&TASK->kernel_box, call);
     309                        ipc_answer(&TASK->kb.box, call);
    310310                        return;
    311311                }
Note: See TracChangeset for help on using the changeset viewer.