Changeset 7509ddc in mainline for generic/src/proc/task.c


Ignore:
Timestamp:
2006-06-04T21:54:49Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
34dcd3f
Parents:
2cb5e64
Message:

Framework for task_kill().
Some pieces (e.g. implementation of ktask_cleanup() kernel thread and
task_destroy() function) are missing.
Changed locking order for task lock, threads_lock and thread lock from
threads_lock, thread lock, task lock to task lock, threads_lock, thread lock.

File:
1 edited

Legend:

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

    r2cb5e64 r7509ddc  
    4848#include <print.h>
    4949#include <elf.h>
     50#include <errno.h>
    5051#include <syscall/copy.h>
    5152
     
    5758btree_t tasks_btree;
    5859static task_id_t task_counter = 0;
     60
     61static void ktask_cleanup(void *);
    5962
    6063/** Initialize tasks
     
    9598        ta->name = name;
    9699
     100        ta->refcount = 0;
     101
    97102        ta->capabilities = 0;
     103        ta->accept_new_threads = true;
    98104       
    99105        ipc_answerbox_init(&ta->answerbox);
     
    128134}
    129135
     136/** Destroy task.
     137 *
     138 * @param t Task to be destroyed.
     139 */
     140void task_destroy(task_t *t)
     141{
     142}
     143
    130144/** Create new task with 1 thread and run it
    131145 *
     
    206220       
    207221        return (task_t *) btree_search(&tasks_btree, (btree_key_t) id, &leaf);
     222}
     223
     224/** Kill task.
     225 *
     226 * @param id ID of the task to be killed.
     227 *
     228 * @return 0 on success or an error code from errno.h
     229 */
     230int task_kill(task_id_t id)
     231{
     232        ipl_t ipl;
     233        task_t *ta;
     234        thread_t *t;
     235        link_t *cur;
     236       
     237        ipl = interrupts_disable();
     238        spinlock_lock(&tasks_lock);
     239
     240        if (!(ta = task_find_by_id(id))) {
     241                spinlock_unlock(&tasks_lock);
     242                interrupts_restore(ipl);
     243                return ENOENT;
     244        }
     245       
     246        spinlock_lock(&ta->lock);
     247        ta->refcount++;
     248        spinlock_unlock(&ta->lock);
     249       
     250        t = thread_create(ktask_cleanup, NULL, ta, 0, "ktask_cleanup");
     251       
     252        spinlock_lock(&ta->lock);
     253        ta->refcount--;
     254       
     255        for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) {
     256                thread_t *thr;
     257                bool  sleeping = false;
     258               
     259                thr = list_get_instance(cur, thread_t, th_link);
     260                if (thr == t)
     261                        continue;
     262                       
     263                spinlock_lock(&thr->lock);
     264                thr->interrupted = true;
     265                if (thr->state == Sleeping)
     266                        sleeping = true;
     267                spinlock_unlock(&thr->lock);
     268               
     269                if (sleeping)
     270                        waitq_interrupt_sleep(thr);
     271        }
     272       
     273        thread_ready(t);
     274       
     275        return 0;
    208276}
    209277
     
    244312        interrupts_restore(ipl);
    245313}
     314
     315/** Kernel thread used to cleanup the task. */
     316void ktask_cleanup(void *arg)
     317{
     318        /*
     319         * TODO:
     320         * Wait until it is save to cleanup the task (i.e. all other threads exit)
     321         * and do the cleanup (e.g. close IPC communication and release used futexes).
     322         * When this thread exits, the task refcount drops to zero and the task structure is
     323         * cleaned.
     324         */
     325}
Note: See TracChangeset for help on using the changeset viewer.