Rev 2187 | Rev 2229 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2187 | Rev 2216 | ||
---|---|---|---|
Line 92... | Line 92... | ||
92 | * exist as long as the threads_lock is held. |
92 | * exist as long as the threads_lock is held. |
93 | */ |
93 | */ |
94 | btree_t threads_btree; |
94 | btree_t threads_btree; |
95 | 95 | ||
96 | SPINLOCK_INITIALIZE(tidlock); |
96 | SPINLOCK_INITIALIZE(tidlock); |
97 | uint32_t last_tid = 0; |
97 | thread_id_t last_tid = 0; |
98 | 98 | ||
99 | static slab_cache_t *thread_slab; |
99 | static slab_cache_t *thread_slab; |
100 | #ifdef ARCH_HAS_FPU |
100 | #ifdef ARCH_HAS_FPU |
101 | slab_cache_t *fpu_context_slab; |
101 | slab_cache_t *fpu_context_slab; |
102 | #endif |
102 | #endif |
Line 578... | Line 578... | ||
578 | 578 | ||
579 | uint64_t cycles; |
579 | uint64_t cycles; |
580 | char suffix; |
580 | char suffix; |
581 | order(t->cycles, &cycles, &suffix); |
581 | order(t->cycles, &cycles, &suffix); |
582 | 582 | ||
583 | printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx " |
583 | printf("%-6llu %-10s %#10zx %-8s %#10zx %-3ld %#10zx " |
584 | "%#10zx %9llu%c ", t->tid, t->name, t, |
584 | "%#10zx %9llu%c ", t->tid, t->name, t, |
585 | thread_states[t->state], t->task, t->task->context, |
585 | thread_states[t->state], t->task, t->task->context, |
586 | t->thread_code, t->kstack, cycles, suffix); |
586 | t->thread_code, t->kstack, cycles, suffix); |
587 | 587 | ||
588 | if (t->cpu) |
588 | if (t->cpu) |
Line 634... | Line 634... | ||
634 | } |
634 | } |
635 | 635 | ||
636 | /** Process syscall to create new thread. |
636 | /** Process syscall to create new thread. |
637 | * |
637 | * |
638 | */ |
638 | */ |
639 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name) |
639 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name, thread_id_t *uspace_thread_id) |
640 | { |
640 | { |
641 | thread_t *t; |
641 | thread_t *t; |
642 | char namebuf[THREAD_NAME_BUFLEN]; |
642 | char namebuf[THREAD_NAME_BUFLEN]; |
643 | uspace_arg_t *kernel_uarg; |
643 | uspace_arg_t *kernel_uarg; |
644 | uint32_t tid; |
- | |
645 | int rc; |
644 | int rc; |
646 | 645 | ||
647 | rc = copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN); |
646 | rc = copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN); |
648 | if (rc != 0) |
647 | if (rc != 0) |
649 | return (unative_t) rc; |
648 | return (unative_t) rc; |
Line 656... | Line 655... | ||
656 | } |
655 | } |
657 | 656 | ||
658 | t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, |
657 | t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, |
659 | false); |
658 | false); |
660 | if (t) { |
659 | if (t) { |
661 | tid = t->tid; |
- | |
662 | thread_ready(t); |
660 | thread_ready(t); |
- | 661 | if (uspace_thread_id != NULL) |
|
- | 662 | return (unative_t) copy_to_uspace(uspace_thread_id, &t->tid, |
|
663 | return (unative_t) tid; |
663 | sizeof(t->tid)); |
- | 664 | else |
|
- | 665 | return 0; |
|
664 | } else { |
666 | } else |
665 | free(kernel_uarg); |
667 | free(kernel_uarg); |
666 | } |
- | |
667 | 668 | ||
668 | return (unative_t) ENOMEM; |
669 | return (unative_t) ENOMEM; |
669 | } |
670 | } |
670 | 671 | ||
671 | /** Process syscall to terminate thread. |
672 | /** Process syscall to terminate thread. |
Line 678... | Line 679... | ||
678 | return 0; |
679 | return 0; |
679 | } |
680 | } |
680 | 681 | ||
681 | /** Syscall for getting TID. |
682 | /** Syscall for getting TID. |
682 | * |
683 | * |
- | 684 | * @param uspace_thread_id Userspace address of 8-byte buffer where to store |
|
683 | * @return Thread ID. |
685 | * current thread ID. |
- | 686 | * |
|
- | 687 | * @return 0 on success or an error code from @ref errno.h. |
|
684 | */ |
688 | */ |
685 | unative_t sys_thread_get_id(void) |
689 | unative_t sys_thread_get_id(thread_id_t *uspace_thread_id) |
686 | { |
690 | { |
687 | /* |
691 | /* |
688 | * No need to acquire lock on THREAD because tid |
692 | * No need to acquire lock on THREAD because tid |
689 | * remains constant for the lifespan of the thread. |
693 | * remains constant for the lifespan of the thread. |
690 | */ |
694 | */ |
- | 695 | return (unative_t) copy_to_uspace(uspace_thread_id, &THREAD->tid, |
|
691 | return THREAD->tid; |
696 | sizeof(THREAD->tid)); |
692 | } |
697 | } |
693 | 698 | ||
694 | /** @} |
699 | /** @} |
695 | */ |
700 | */ |