Ignore:
File:
1 edited

Legend:

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

    r41df2827 r40240b1  
    5454#include <func.h>
    5555#include <string.h>
    56 #include <memstr.h>
    5756#include <syscall/copy.h>
    5857#include <macros.h>
     
    7675static task_id_t task_counter = 0;
    7776
    78 static slab_cache_t *task_slab;
    79 
    8077/* Forward declarations. */
    8178static void task_kill_internal(task_t *);
    82 static int tsk_constructor(void *, int);
    8379
    8480/** Initialize kernel tasks support. */
     
    8783        TASK = NULL;
    8884        avltree_create(&tasks_tree);
    89         task_slab = slab_cache_create("task_slab", sizeof(task_t), 0,
    90             tsk_constructor, NULL, 0);
    9185}
    9286
     
    134128}
    135129
    136 int tsk_constructor(void *obj, int kmflags)
    137 {
    138         task_t *ta = obj;
     130/** Create new task with no threads.
     131 *
     132 * @param as            Task's address space.
     133 * @param name          Symbolic name (a copy is made).
     134 *
     135 * @return              New task's structure.
     136 *
     137 */
     138task_t *task_create(as_t *as, char *name)
     139{
     140        ipl_t ipl;
     141        task_t *ta;
    139142        int i;
     143       
     144        ta = (task_t *) malloc(sizeof(task_t), 0);
     145
     146        task_create_arch(ta);
     147
     148        spinlock_initialize(&ta->lock, "task_ta_lock");
     149        list_initialize(&ta->th_head);
     150        ta->as = as;
     151
     152        memcpy(ta->name, name, TASK_NAME_BUFLEN);
     153        ta->name[TASK_NAME_BUFLEN - 1] = 0;
    140154
    141155        atomic_set(&ta->refcount, 0);
    142156        atomic_set(&ta->lifecount, 0);
    143         atomic_set(&ta->active_calls, 0);
    144 
    145         spinlock_initialize(&ta->lock, "task_ta_lock");
    146         mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
    147 
    148         list_initialize(&ta->th_head);
    149         list_initialize(&ta->sync_box_head);
     157        ta->context = CONTEXT;
     158
     159        ta->capabilities = 0;
     160        ta->cycles = 0;
     161
     162#ifdef CONFIG_UDEBUG
     163        /* Init debugging stuff */
     164        udebug_task_init(&ta->udebug);
     165
     166        /* Init kbox stuff */
     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;
     171#endif
    150172
    151173        ipc_answerbox_init(&ta->answerbox, ta);
    152174        for (i = 0; i < IPC_MAX_PHONES; i++)
    153175                ipc_phone_init(&ta->phones[i]);
    154 
    155 #ifdef CONFIG_UDEBUG
    156         /* Init kbox stuff */
    157         ta->kb.thread = NULL;
    158         ipc_answerbox_init(&ta->kb.box, ta);
    159         mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
    160 #endif
    161 
    162         return 0;
    163 }
    164 
    165 /** Create new task with no threads.
    166  *
    167  * @param as            Task's address space.
    168  * @param name          Symbolic name (a copy is made).
    169  *
    170  * @return              New task's structure.
    171  *
    172  */
    173 task_t *task_create(as_t *as, char *name)
    174 {
    175         ipl_t ipl;
    176         task_t *ta;
    177        
    178         ta = (task_t *) slab_alloc(task_slab, 0);
    179         task_create_arch(ta);
    180         ta->as = as;
    181         memcpy(ta->name, name, TASK_NAME_BUFLEN);
    182         ta->name[TASK_NAME_BUFLEN - 1] = 0;
    183 
    184         ta->context = CONTEXT;
    185         ta->capabilities = 0;
    186         ta->cycles = 0;
    187 
    188 #ifdef CONFIG_UDEBUG
    189         /* Init debugging stuff */
    190         udebug_task_init(&ta->udebug);
    191 
    192         /* Init kbox stuff */
    193         ta->kb.finished = false;
    194 #endif
    195 
    196         if ((ipc_phone_0) &&
    197             (context_check(ipc_phone_0->task->context, ta->context)))
     176        if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context,
     177            ta->context)))
    198178                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    199 
     179        atomic_set(&ta->active_calls, 0);
     180
     181        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
    200182        btree_create(&ta->futexes);
    201183       
    202184        ipl = interrupts_disable();
     185
     186        /*
     187         * Increment address space reference count.
     188         */
    203189        atomic_inc(&as->refcount);
     190
    204191        spinlock_lock(&tasks_lock);
    205192        ta->taskid = ++task_counter;
     
    242229                as_destroy(t->as);
    243230       
    244         slab_free(task_slab, t);
     231        free(t);
    245232        TASK = NULL;
    246233}
Note: See TracChangeset for help on using the changeset viewer.