Rev 1579 | Rev 1583 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1579 | Rev 1580 | ||
---|---|---|---|
Line 56... | Line 56... | ||
56 | 56 | ||
57 | SPINLOCK_INITIALIZE(tasks_lock); |
57 | SPINLOCK_INITIALIZE(tasks_lock); |
58 | btree_t tasks_btree; |
58 | btree_t tasks_btree; |
59 | static task_id_t task_counter = 0; |
59 | static task_id_t task_counter = 0; |
60 | 60 | ||
61 | static void ktask_cleanup(void *); |
61 | static void ktaskclnp(void *); |
62 | 62 | ||
63 | /** Initialize tasks |
63 | /** Initialize tasks |
64 | * |
64 | * |
65 | * Initialize kernel tasks support. |
65 | * Initialize kernel tasks support. |
66 | * |
66 | * |
Line 245... | Line 245... | ||
245 | 245 | ||
246 | spinlock_lock(&ta->lock); |
246 | spinlock_lock(&ta->lock); |
247 | ta->refcount++; |
247 | ta->refcount++; |
248 | spinlock_unlock(&ta->lock); |
248 | spinlock_unlock(&ta->lock); |
249 | 249 | ||
250 | t = thread_create(ktask_cleanup, NULL, ta, 0, "ktask_cleanup"); |
250 | t = thread_create(ktaskclnp, NULL, ta, 0, "ktaskclnp"); |
251 | 251 | ||
252 | spinlock_lock(&ta->lock); |
252 | spinlock_lock(&ta->lock); |
- | 253 | ta->accept_new_threads = false; |
|
253 | ta->refcount--; |
254 | ta->refcount--; |
254 | 255 | ||
255 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
256 | for (cur = ta->th_head.next; cur != &ta->th_head; cur = cur->next) { |
256 | thread_t *thr; |
257 | thread_t *thr; |
257 | bool sleeping = false; |
258 | bool sleeping = false; |
Line 268... | Line 269... | ||
268 | 269 | ||
269 | if (sleeping) |
270 | if (sleeping) |
270 | waitq_interrupt_sleep(thr); |
271 | waitq_interrupt_sleep(thr); |
271 | } |
272 | } |
272 | 273 | ||
- | 274 | spinlock_unlock(&ta->lock); |
|
273 | thread_ready(t); |
275 | interrupts_restore(ipl); |
274 | 276 | ||
- | 277 | if (t) |
|
- | 278 | thread_ready(t); |
|
- | 279 | ||
275 | return 0; |
280 | return 0; |
276 | } |
281 | } |
277 | 282 | ||
278 | /** Print task list */ |
283 | /** Print task list */ |
279 | void task_print_list(void) |
284 | void task_print_list(void) |
Line 311... | Line 316... | ||
311 | spinlock_unlock(&tasks_lock); |
316 | spinlock_unlock(&tasks_lock); |
312 | interrupts_restore(ipl); |
317 | interrupts_restore(ipl); |
313 | } |
318 | } |
314 | 319 | ||
315 | /** Kernel thread used to cleanup the task. */ |
320 | /** Kernel thread used to cleanup the task. */ |
316 | void ktask_cleanup(void *arg) |
321 | void ktaskclnp(void *arg) |
317 | { |
322 | { |
- | 323 | ipl_t ipl; |
|
- | 324 | thread_t *t = NULL; |
|
- | 325 | link_t *cur; |
|
- | 326 | ||
- | 327 | thread_detach(THREAD); |
|
- | 328 | ||
- | 329 | loop: |
|
- | 330 | ipl = interrupts_disable(); |
|
- | 331 | spinlock_lock(&TASK->lock); |
|
- | 332 | ||
- | 333 | /* |
|
- | 334 | * Find a thread to join. |
|
- | 335 | */ |
|
- | 336 | for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) { |
|
- | 337 | t = list_get_instance(cur, thread_t, th_link); |
|
- | 338 | if (t == THREAD) |
|
- | 339 | continue; |
|
- | 340 | else |
|
- | 341 | break; |
|
- | 342 | } |
|
- | 343 | ||
- | 344 | spinlock_unlock(&TASK->lock); |
|
- | 345 | interrupts_restore(ipl); |
|
- | 346 | ||
- | 347 | if (t != THREAD) { |
|
- | 348 | thread_join(t); |
|
- | 349 | thread_detach(t); |
|
- | 350 | goto loop; |
|
- | 351 | } |
|
- | 352 | ||
- | 353 | /* |
|
- | 354 | * Now there are no other threads in this task |
|
- | 355 | * and no new threads can be created. |
|
- | 356 | */ |
|
- | 357 | ||
318 | /* |
358 | /* |
319 | * TODO: |
359 | * 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). |
360 | * Close IPC communication and release used futexes. |
322 | * When this thread exits, the task refcount drops to zero and the task structure is |
361 | * When this thread exits, the task refcount drops to zero and the task structure is |
323 | * cleaned. |
362 | * cleaned. |
324 | */ |
363 | */ |
325 | } |
364 | } |