Rev 2787 | Rev 2801 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 2799 | ||
---|---|---|---|
Line 66... | Line 66... | ||
66 | #include <debug.h> |
66 | #include <debug.h> |
67 | #include <main/uinit.h> |
67 | #include <main/uinit.h> |
68 | #include <syscall/copy.h> |
68 | #include <syscall/copy.h> |
69 | #include <errno.h> |
69 | #include <errno.h> |
70 | #include <console/klog.h> |
70 | #include <console/klog.h> |
71 | #include <tdebug/tdebug.h> |
- | |
72 | 71 | ||
73 | 72 | ||
74 | /** Thread states */ |
73 | /** Thread states */ |
75 | char *thread_states[] = { |
74 | char *thread_states[] = { |
76 | "Invalid", |
75 | "Invalid", |
Line 340... | Line 339... | ||
340 | t->fpu_context_exists = 0; |
339 | t->fpu_context_exists = 0; |
341 | t->fpu_context_engaged = 0; |
340 | t->fpu_context_engaged = 0; |
342 | 341 | ||
343 | avltree_node_initialize(&t->threads_tree_node); |
342 | avltree_node_initialize(&t->threads_tree_node); |
344 | t->threads_tree_node.key = (uintptr_t) t; |
343 | t->threads_tree_node.key = (uintptr_t) t; |
345 | // t->threads_tree_node.key = (avltree_key_t) t->tid; |
- | |
346 | 344 | ||
347 | /* might depend on previous initialization */ |
345 | /* might depend on previous initialization */ |
348 | thread_create_arch(t); |
346 | thread_create_arch(t); |
349 | - | ||
350 | /* init tdebug stuff */ |
- | |
351 | tdebug_thread_init(t); |
- | |
352 | 347 | ||
353 | if (!(flags & THREAD_FLAG_NOATTACH)) |
348 | if (!(flags & THREAD_FLAG_NOATTACH)) |
354 | thread_attach(t, task); |
349 | thread_attach(t, task); |
355 | 350 | ||
356 | return t; |
351 | return t; |
Line 445... | Line 440... | ||
445 | * We are safe to perform cleanup. |
440 | * We are safe to perform cleanup. |
446 | */ |
441 | */ |
447 | if (THREAD->flags & THREAD_FLAG_USPACE) { |
442 | if (THREAD->flags & THREAD_FLAG_USPACE) { |
448 | ipc_cleanup(); |
443 | ipc_cleanup(); |
449 | futex_cleanup(); |
444 | futex_cleanup(); |
450 | tdebug_cleanup(); |
- | |
451 | klog_printf("Cleanup of task %llu completed.", |
445 | klog_printf("Cleanup of task %llu completed.", |
452 | TASK->taskid); |
446 | TASK->taskid); |
453 | } |
447 | } |
454 | } |
448 | } |
455 | 449 | ||
Line 753... | Line 747... | ||
753 | thread_exit(); |
747 | thread_exit(); |
754 | /* Unreachable */ |
748 | /* Unreachable */ |
755 | return 0; |
749 | return 0; |
756 | } |
750 | } |
757 | 751 | ||
758 | struct fbiw { |
- | |
759 | thread_id_t tid; |
- | |
760 | thread_t *t; |
- | |
761 | }; |
- | |
762 | - | ||
763 | static bool find_by_id_walker(avltree_node_t *node, void *arg) |
- | |
764 | { |
- | |
765 | thread_t *t = avltree_get_instance(node, thread_t, threads_tree_node); |
- | |
766 | struct fbiw *s = (struct fbiw *)arg; |
- | |
767 | - | ||
768 | if (t->tid == s->tid) { |
- | |
769 | /* found it! */ |
- | |
770 | s->t = t; |
- | |
771 | return false; |
- | |
772 | } |
- | |
773 | - | ||
774 | return true; /* continue */ |
- | |
775 | } |
- | |
776 | - | ||
777 | /** Find thread structure corresponding to thread ID. |
- | |
778 | * |
- | |
779 | * The threads_lock must be already held by the caller of this function |
- | |
780 | * and interrupts must be disabled. |
- | |
781 | * |
- | |
782 | * @param id Thread ID. |
- | |
783 | * |
- | |
784 | * @return Thread structure address or NULL if there is no such thread ID. |
- | |
785 | */ |
- | |
786 | thread_t *thread_find_by_id(thread_id_t id) |
- | |
787 | { |
- | |
788 | struct fbiw s; |
- | |
789 | - | ||
790 | s.t = NULL; |
- | |
791 | s.tid = id; |
- | |
792 | - | ||
793 | avltree_walk(&threads_tree, find_by_id_walker, &s); |
- | |
794 | - | ||
795 | return s.t; |
- | |
796 | /* |
- | |
797 | // ANO, takhle krasne by to fungovalo, kdyby threads_tree |
- | |
798 | // nepouzival jako klic pointer na vlakno misto tid |
- | |
799 | avltree_node_t *node; |
- | |
800 | |
- | |
801 | node = avltree_search(&threads_tree, (avltree_key_t) id); |
- | |
802 | - | ||
803 | if (node) |
- | |
804 | return avltree_get_instance(node, thread_t, threads_tree_node); |
- | |
805 | return NULL;*/ |
- | |
806 | } |
- | |
807 | - | ||
808 | /** Syscall for getting TID. |
752 | /** Syscall for getting TID. |
809 | * |
753 | * |
810 | * @param uspace_thread_id Userspace address of 8-byte buffer where to store |
754 | * @param uspace_thread_id Userspace address of 8-byte buffer where to store |
811 | * current thread ID. |
755 | * current thread ID. |
812 | * |
756 | * |