Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/task.c

    r5a6cc679 ra35b458  
    5656#include <print.h>
    5757#include <errno.h>
    58 #include <func.h>
     58#include <halt.h>
    5959#include <str.h>
    6060#include <syscall/copy.h>
     
    107107        task_t *task = avltree_get_instance(node, task_t, tasks_tree_node);
    108108        size_t *cnt = (size_t *) arg;
    109        
     109
    110110        if (task != TASK) {
    111111                (*cnt)++;
    112                
     112
    113113#ifdef CONFIG_DEBUG
    114114                printf("[%"PRIu64"] ", task->taskid);
    115115#endif
    116                
     116
    117117                task_kill_internal(task);
    118118        }
    119        
     119
    120120        /* Continue the walk */
    121121        return true;
     
    138138                task_release(task_0);
    139139        }
    140        
     140
    141141        /* Repeat until there are any tasks except TASK */
    142142        do {
     
    144144                printf("Killing tasks... ");
    145145#endif
    146                
     146
    147147                irq_spinlock_lock(&tasks_lock, true);
    148148                tasks_left = 0;
    149149                avltree_walk(&tasks_tree, task_done_walker, &tasks_left);
    150150                irq_spinlock_unlock(&tasks_lock, true);
    151                
     151
    152152                thread_sleep(1);
    153                
     153
    154154#ifdef CONFIG_DEBUG
    155155                printf("\n");
     
    165165        if (rc != EOK)
    166166                return rc;
    167        
     167
    168168        atomic_set(&task->refcount, 0);
    169169        atomic_set(&task->lifecount, 0);
    170        
     170
    171171        irq_spinlock_initialize(&task->lock, "task_t_lock");
    172        
     172
    173173        list_initialize(&task->threads);
    174        
     174
    175175        ipc_answerbox_init(&task->answerbox, task);
    176        
     176
    177177        spinlock_initialize(&task->active_calls_lock, "active_calls_lock");
    178178        list_initialize(&task->active_calls);
    179                
     179
    180180#ifdef CONFIG_UDEBUG
    181181        /* Init kbox stuff */
     
    184184        mutex_initialize(&task->kb.cleanup_lock, MUTEX_PASSIVE);
    185185#endif
    186        
     186
    187187        return EOK;
    188188}
     
    191191{
    192192        task_t *task = (task_t *) obj;
    193        
     193
    194194        caps_task_free(task);
    195195        return 0;
     
    210210                return NULL;
    211211        }
    212        
     212
    213213        task_create_arch(task);
    214        
     214
    215215        task->as = as;
    216216        str_cpy(task->name, TASK_NAME_BUFLEN, name);
    217        
     217
    218218        task->container = CONTAINER;
    219219        task->perms = 0;
     
    231231
    232232        event_task_init(task);
    233        
     233
    234234        task->answerbox.active = true;
    235235
     
    237237        /* Init debugging stuff */
    238238        udebug_task_init(&task->udebug);
    239        
     239
    240240        /* Init kbox stuff */
    241241        task->kb.box.active = true;
    242242        task->kb.finished = false;
    243243#endif
    244        
     244
    245245        if ((ipc_phone_0) &&
    246246            (container_check(ipc_phone_0->task->container, task->container))) {
     
    253253                        return NULL;
    254254                }
    255                
     255
    256256                kobject_t *phone_obj = kobject_get(task, phone_handle,
    257257                    KOBJECT_TYPE_PHONE);
    258258                (void) ipc_phone_connect(phone_obj->phone, ipc_phone_0);
    259259        }
    260        
     260
    261261        futex_task_init(task);
    262        
     262
    263263        /*
    264264         * Get a reference to the address space.
    265265         */
    266266        as_hold(task->as);
    267        
     267
    268268        irq_spinlock_lock(&tasks_lock, true);
    269        
     269
    270270        task->taskid = ++task_counter;
    271271        avltree_node_initialize(&task->tasks_tree_node);
    272272        task->tasks_tree_node.key = task->taskid;
    273273        avltree_insert(&tasks_tree, &task->tasks_tree_node);
    274        
     274
    275275        irq_spinlock_unlock(&tasks_lock, true);
    276        
     276
    277277        return task;
    278278}
     
    291291        avltree_delete(&tasks_tree, &task->tasks_tree_node);
    292292        irq_spinlock_unlock(&tasks_lock, true);
    293        
     293
    294294        /*
    295295         * Perform architecture specific task destruction.
    296296         */
    297297        task_destroy_arch(task);
    298        
     298
    299299        /*
    300300         * Free up dynamically allocated state.
    301301         */
    302302        futex_task_deinit(task);
    303        
     303
    304304        /*
    305305         * Drop our reference to the address space.
    306306         */
    307307        as_release(task->as);
    308        
     308
    309309        slab_free(task_cache, task);
    310310}
     
    388388{
    389389        char namebuf[TASK_NAME_BUFLEN];
    390        
     390
    391391        /* Cap length of name and copy it from userspace. */
    392392        if (name_len > TASK_NAME_BUFLEN - 1)
    393393                name_len = TASK_NAME_BUFLEN - 1;
    394        
     394
    395395        errno_t rc = copy_from_uspace(namebuf, uspace_name, name_len);
    396396        if (rc != EOK)
    397397                return (sys_errno_t) rc;
    398        
     398
    399399        namebuf[name_len] = '\0';
    400        
     400
    401401        /*
    402402         * As the task name is referenced also from the
     
    404404         * of the update.
    405405         */
    406        
     406
    407407        irq_spinlock_lock(&tasks_lock, true);
    408408        irq_spinlock_lock(&TASK->lock, false);
    409409        irq_spinlock_lock(&threads_lock, false);
    410        
     410
    411411        /* Set task name */
    412412        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    413        
     413
    414414        irq_spinlock_unlock(&threads_lock, false);
    415415        irq_spinlock_unlock(&TASK->lock, false);
    416416        irq_spinlock_unlock(&tasks_lock, true);
    417        
     417
    418418        return EOK;
    419419}
     
    432432        if (rc != EOK)
    433433                return (sys_errno_t) rc;
    434        
     434
    435435        return (sys_errno_t) task_kill(taskid);
    436436}
     
    453453        avltree_node_t *node =
    454454            avltree_search(&tasks_tree, (avltree_key_t) id);
    455        
     455
    456456        if (node)
    457457                return avltree_get_instance(node, task_t, tasks_tree_node);
    458        
     458
    459459        return NULL;
    460460}
     
    478478        uint64_t uret = task->ucycles;
    479479        uint64_t kret = task->kcycles;
    480        
     480
    481481        /* Current values of threads */
    482482        list_foreach(task->threads, th_link, thread_t, thread) {
    483483                irq_spinlock_lock(&thread->lock, false);
    484                
     484
    485485                /* Process only counted threads */
    486486                if (!thread->uncounted) {
     
    489489                                thread_update_accounting(false);
    490490                        }
    491                        
     491
    492492                        uret += thread->ucycles;
    493493                        kret += thread->kcycles;
    494494                }
    495                
     495
    496496                irq_spinlock_unlock(&thread->lock, false);
    497497        }
    498        
     498
    499499        *ucycles = uret;
    500500        *kcycles = kret;
     
    505505        irq_spinlock_lock(&task->lock, false);
    506506        irq_spinlock_lock(&threads_lock, false);
    507        
     507
    508508        /*
    509509         * Interrupt all threads.
    510510         */
    511        
     511
    512512        list_foreach(task->threads, th_link, thread_t, thread) {
    513513                bool sleeping = false;
    514                
     514
    515515                irq_spinlock_lock(&thread->lock, false);
    516                
     516
    517517                thread->interrupted = true;
    518518                if (thread->state == Sleeping)
    519519                        sleeping = true;
    520                
     520
    521521                irq_spinlock_unlock(&thread->lock, false);
    522                
     522
    523523                if (sleeping)
    524524                        waitq_interrupt_sleep(thread);
    525525        }
    526        
     526
    527527        irq_spinlock_unlock(&threads_lock, false);
    528528        irq_spinlock_unlock(&task->lock, false);
     
    543543        if (id == 1)
    544544                return EPERM;
    545        
     545
    546546        irq_spinlock_lock(&tasks_lock, true);
    547        
     547
    548548        task_t *task = task_find_by_id(id);
    549549        if (!task) {
     
    551551                return ENOENT;
    552552        }
    553        
     553
    554554        task_kill_internal(task);
    555555        irq_spinlock_unlock(&tasks_lock, true);
    556        
     556
    557557        return EOK;
    558558}
     
    583583                }
    584584        }
    585        
     585
    586586        irq_spinlock_lock(&tasks_lock, true);
    587587        task_kill_internal(TASK);
    588588        irq_spinlock_unlock(&tasks_lock, true);
    589        
     589
    590590        thread_exit();
    591591}
     
    599599{
    600600        task_kill_self(notify);
    601        
     601
    602602        /* Unreachable */
    603603        return EOK;
     
    609609        task_t *task = avltree_get_instance(node, task_t, tasks_tree_node);
    610610        irq_spinlock_lock(&task->lock, false);
    611        
     611
    612612        uint64_t ucycles;
    613613        uint64_t kcycles;
     
    616616        order_suffix(ucycles, &ucycles, &usuffix);
    617617        order_suffix(kcycles, &kcycles, &ksuffix);
    618        
     618
    619619#ifdef __32_BITS__
    620620        if (*additional)
     
    627627                    ucycles, usuffix, kcycles, ksuffix);
    628628#endif
    629        
     629
    630630#ifdef __64_BITS__
    631631        if (*additional)
     
    637637                    task->taskid, task->name, task->container, task, task->as);
    638638#endif
    639        
     639
    640640        irq_spinlock_unlock(&task->lock, false);
    641641        return true;
     
    651651        /* Messing with task structures, avoid deadlock */
    652652        irq_spinlock_lock(&tasks_lock, true);
    653        
     653
    654654#ifdef __32_BITS__
    655655        if (additional)
     
    659659                    " [ucycles ] [kcycles ]\n");
    660660#endif
    661        
     661
    662662#ifdef __64_BITS__
    663663        if (additional)
     
    668668                    " [as              ]\n");
    669669#endif
    670        
     670
    671671        avltree_walk(&tasks_tree, task_print_walker, &additional);
    672        
     672
    673673        irq_spinlock_unlock(&tasks_lock, true);
    674674}
Note: See TracChangeset for help on using the changeset viewer.