Subversion Repositories HelenOS-historic

Rev

Rev 1115 | Rev 1168 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1115 Rev 1159
Line 33... Line 33...
33
#include <mm/as.h>
33
#include <mm/as.h>
34
#include <mm/slab.h>
34
#include <mm/slab.h>
35
#include <synch/spinlock.h>
35
#include <synch/spinlock.h>
36
#include <arch.h>
36
#include <arch.h>
37
#include <panic.h>
37
#include <panic.h>
-
 
38
#include <adt/btree.h>
38
#include <adt/list.h>
39
#include <adt/list.h>
39
#include <ipc/ipc.h>
40
#include <ipc/ipc.h>
40
#include <memstr.h>
41
#include <memstr.h>
41
#include <print.h>
42
#include <print.h>
42
#include <elf.h>
43
#include <elf.h>
43
 
44
 
44
SPINLOCK_INITIALIZE(tasks_lock);
45
SPINLOCK_INITIALIZE(tasks_lock);
45
LIST_INITIALIZE(tasks_head);
46
btree_t tasks_btree;
46
static task_id_t task_counter = 0;
47
static task_id_t task_counter = 0;
47
 
48
 
48
/** Initialize tasks
49
/** Initialize tasks
49
 *
50
 *
50
 * Initialize kernel tasks support.
51
 * Initialize kernel tasks support.
51
 *
52
 *
52
 */
53
 */
53
void task_init(void)
54
void task_init(void)
54
{
55
{
55
    TASK = NULL;
56
    TASK = NULL;
-
 
57
    btree_create(&tasks_btree);
56
}
58
}
57
 
59
 
58
 
60
 
59
/** Create new task
61
/** Create new task
60
 *
62
 *
Line 74... Line 76...
74
   
76
   
75
    ta = (task_t *) malloc(sizeof(task_t), 0);
77
    ta = (task_t *) malloc(sizeof(task_t), 0);
76
 
78
 
77
    spinlock_initialize(&ta->lock, "task_ta_lock");
79
    spinlock_initialize(&ta->lock, "task_ta_lock");
78
    list_initialize(&ta->th_head);
80
    list_initialize(&ta->th_head);
79
    list_initialize(&ta->tasks_link);
-
 
80
    ta->as = as;
81
    ta->as = as;
81
    ta->name = name;
82
    ta->name = name;
82
 
83
 
83
   
84
   
84
    ipc_answerbox_init(&ta->answerbox);
85
    ipc_answerbox_init(&ta->answerbox);
Line 90... Line 91...
90
   
91
   
91
    ipl = interrupts_disable();
92
    ipl = interrupts_disable();
92
    spinlock_lock(&tasks_lock);
93
    spinlock_lock(&tasks_lock);
93
 
94
 
94
    ta->taskid = ++task_counter;
95
    ta->taskid = ++task_counter;
95
    list_append(&ta->tasks_link, &tasks_head);
96
    btree_insert(&tasks_btree, (__native) ta, (void *) ta, NULL);
96
 
97
 
97
    spinlock_unlock(&tasks_lock);
98
    spinlock_unlock(&tasks_lock);
98
    interrupts_restore(ipl);
99
    interrupts_restore(ipl);
99
 
100
 
100
    return ta;
101
    return ta;
Line 149... Line 150...
149
 
150
 
150
/** Print task list */
151
/** Print task list */
151
void task_print_list(void)
152
void task_print_list(void)
152
{
153
{
153
    link_t *cur;
154
    link_t *cur;
154
    task_t *t;
-
 
155
    ipl_t ipl;
155
    ipl_t ipl;
156
    int i;
-
 
157
   
156
   
158
    /* Messing with thread structures, avoid deadlock */
157
    /* Messing with thread structures, avoid deadlock */
159
    ipl = interrupts_disable();
158
    ipl = interrupts_disable();
160
    spinlock_lock(&tasks_lock);
159
    spinlock_lock(&tasks_lock);
161
 
160
 
162
    for (cur=tasks_head.next; cur!=&tasks_head; cur=cur->next) {
161
    for (cur = tasks_btree.leaf_head.next; cur != &tasks_btree.leaf_head; cur = cur->next) {
-
 
162
        btree_node_t *node;
-
 
163
        int i;
-
 
164
       
163
        t = list_get_instance(cur, task_t, tasks_link);
165
        node = list_get_instance(cur, btree_node_t, leaf_link);
-
 
166
        for (i = 0; i < node->keys; i++) {
-
 
167
            task_t *t;
-
 
168
            int j;
-
 
169
 
-
 
170
            t = (task_t *) node->value[i];
-
 
171
       
164
        spinlock_lock(&t->lock);
172
            spinlock_lock(&t->lock);
165
        printf("%s: address=%P, taskid=%Q, as=%P, ActiveCalls: %d",
173
            printf("%s: address=%P, taskid=%Q, as=%P, ActiveCalls: %d",
166
            t->name, t, t->taskid, t->as, atomic_get(&t->active_calls));
174
                t->name, t, t->taskid, t->as, atomic_get(&t->active_calls));
167
        for (i=0; i < IPC_MAX_PHONES; i++) {
175
            for (j=0; j < IPC_MAX_PHONES; j++) {
168
            if (t->phones[i].callee)
176
                if (t->phones[j].callee)
169
                printf(" Ph(%d): %P ", i,t->phones[i].callee);
177
                    printf(" Ph(%d): %P ", j, t->phones[j].callee);
-
 
178
            }
-
 
179
            printf("\n");
-
 
180
            spinlock_unlock(&t->lock);
170
        }
181
        }
171
        printf("\n");
-
 
172
        spinlock_unlock(&t->lock);
-
 
173
    }
182
    }
174
 
183
 
175
    spinlock_unlock(&tasks_lock);
184
    spinlock_unlock(&tasks_lock);
176
    interrupts_restore(ipl);
185
    interrupts_restore(ipl);
177
   
186