Changeset 59ee56f in mainline for kernel/generic/src/proc/task.c


Ignore:
Timestamp:
2009-11-28T14:38:17Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67392fa
Parents:
e701eb1
Message:

Introduce a task constructor.

File:
1 edited

Legend:

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

    re701eb1 r59ee56f  
    7979/* Forward declarations. */
    8080static void task_kill_internal(task_t *);
     81static int tsk_constructor(void *, int);
    8182
    8283/** Initialize kernel tasks support. */
     
    8586        TASK = NULL;
    8687        avltree_create(&tasks_tree);
    87         task_slab = slab_cache_create("task_slab", sizeof(task_t), 0, NULL,
    88             NULL, 0);
     88        task_slab = slab_cache_create("task_slab", sizeof(task_t), 0,
     89            tsk_constructor, NULL, 0);
    8990}
    9091
     
    132133}
    133134
     135int tsk_constructor(void *obj, int kmflags)
     136{
     137        task_t *ta = obj;
     138        int i;
     139
     140        atomic_set(&ta->refcount, 0);
     141        atomic_set(&ta->lifecount, 0);
     142        atomic_set(&ta->active_calls, 0);
     143
     144        spinlock_initialize(&ta->lock, "task_ta_lock");
     145        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
     146
     147        list_initialize(&ta->th_head);
     148        list_initialize(&ta->sync_box_head);
     149
     150        ipc_answerbox_init(&ta->answerbox, ta);
     151        for (i = 0; i < IPC_MAX_PHONES; i++)
     152                ipc_phone_init(&ta->phones[i]);
     153
     154#ifdef CONFIG_UDEBUG
     155        /* Init kbox stuff */
     156        ta->kb.thread = NULL;
     157        ipc_answerbox_init(&ta->kb.box, ta);
     158        mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
     159#endif
     160
     161        return 0;
     162}
     163
    134164/** Create new task with no threads.
    135165 *
     
    144174        ipl_t ipl;
    145175        task_t *ta;
    146         int i;
    147176       
    148177        ta = (task_t *) slab_alloc(task_slab, 0);
    149 
    150178        task_create_arch(ta);
    151 
    152         spinlock_initialize(&ta->lock, "task_ta_lock");
    153         list_initialize(&ta->th_head);
    154179        ta->as = as;
    155 
    156180        memcpy(ta->name, name, TASK_NAME_BUFLEN);
    157181        ta->name[TASK_NAME_BUFLEN - 1] = 0;
    158182
    159         atomic_set(&ta->refcount, 0);
    160         atomic_set(&ta->lifecount, 0);
    161183        ta->context = CONTEXT;
    162 
    163184        ta->capabilities = 0;
    164185        ta->cycles = 0;
     
    169190
    170191        /* Init kbox stuff */
    171         ipc_answerbox_init(&ta->kb.box, ta);
    172         ta->kb.thread = NULL;
    173         mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
    174192        ta->kb.finished = false;
    175193#endif
    176194
    177         ipc_answerbox_init(&ta->answerbox, ta);
    178         for (i = 0; i < IPC_MAX_PHONES; i++)
    179                 ipc_phone_init(&ta->phones[i]);
    180         if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context,
    181             ta->context)))
     195        if ((ipc_phone_0) &&
     196            (context_check(ipc_phone_0->task->context, ta->context)))
    182197                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    183         atomic_set(&ta->active_calls, 0);
    184         list_initialize(&ta->sync_box_head);
    185 
    186         mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
     198
    187199        btree_create(&ta->futexes);
    188200       
    189201        ipl = interrupts_disable();
    190 
    191         /*
    192          * Increment address space reference count.
    193          */
    194202        atomic_inc(&as->refcount);
    195 
    196203        spinlock_lock(&tasks_lock);
    197204        ta->taskid = ++task_counter;
Note: See TracChangeset for help on using the changeset viewer.