Rev 2118 | Rev 2216 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2118 | Rev 2183 | ||
|---|---|---|---|
| Line 39... | Line 39... | ||
| 39 | #include <proc/thread.h> |
39 | #include <proc/thread.h> |
| 40 | #include <proc/task.h> |
40 | #include <proc/task.h> |
| 41 | #include <proc/uarg.h> |
41 | #include <proc/uarg.h> |
| 42 | #include <mm/as.h> |
42 | #include <mm/as.h> |
| 43 | #include <mm/slab.h> |
43 | #include <mm/slab.h> |
| - | 44 | #include <atomic.h> |
|
| 44 | #include <synch/spinlock.h> |
45 | #include <synch/spinlock.h> |
| 45 | #include <synch/waitq.h> |
46 | #include <synch/waitq.h> |
| 46 | #include <arch.h> |
47 | #include <arch.h> |
| 47 | #include <panic.h> |
48 | #include <panic.h> |
| 48 | #include <adt/btree.h> |
49 | #include <adt/btree.h> |
| Line 138... | Line 139... | ||
| 138 | 139 | ||
| 139 | ipl = interrupts_disable(); |
140 | ipl = interrupts_disable(); |
| 140 | 141 | ||
| 141 | /* |
142 | /* |
| 142 | * Increment address space reference count. |
143 | * Increment address space reference count. |
| 143 | * TODO: Reconsider the locking scheme. |
- | |
| 144 | */ |
144 | */ |
| 145 | mutex_lock(&as->lock); |
145 | atomic_inc(&as->refcount); |
| 146 | as->refcount++; |
- | |
| 147 | mutex_unlock(&as->lock); |
- | |
| 148 | 146 | ||
| 149 | spinlock_lock(&tasks_lock); |
147 | spinlock_lock(&tasks_lock); |
| 150 | 148 | ||
| 151 | ta->taskid = ++task_counter; |
149 | ta->taskid = ++task_counter; |
| 152 | btree_insert(&tasks_btree, (btree_key_t) ta->taskid, (void *) ta, NULL); |
150 | btree_insert(&tasks_btree, (btree_key_t) ta->taskid, (void *) ta, NULL); |
| Line 164... | Line 162... | ||
| 164 | void task_destroy(task_t *t) |
162 | void task_destroy(task_t *t) |
| 165 | { |
163 | { |
| 166 | task_destroy_arch(t); |
164 | task_destroy_arch(t); |
| 167 | btree_destroy(&t->futexes); |
165 | btree_destroy(&t->futexes); |
| 168 | 166 | ||
| 169 | mutex_lock_active(&t->as->lock); |
- | |
| 170 | if (--t->as->refcount == 0) { |
167 | if (atomic_predec(&t->as->refcount) == 0) |
| 171 | mutex_unlock(&t->as->lock); |
- | |
| 172 | as_destroy(t->as); |
168 | as_destroy(t->as); |
| 173 | /* |
- | |
| 174 | * t->as is destroyed. |
- | |
| 175 | */ |
- | |
| 176 | } else |
- | |
| 177 | mutex_unlock(&t->as->lock); |
- | |
| 178 | 169 | ||
| 179 | free(t); |
170 | free(t); |
| 180 | TASK = NULL; |
171 | TASK = NULL; |
| 181 | } |
172 | } |
| 182 | 173 | ||