Rev 2292 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2292 | Rev 2307 | ||
---|---|---|---|
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 236... | Line 236... | ||
236 | 236 | ||
237 | i = (t->priority < RQ_COUNT - 1) ? ++t->priority : t->priority; |
237 | i = (t->priority < RQ_COUNT - 1) ? ++t->priority : t->priority; |
238 | 238 | ||
239 | cpu = CPU; |
239 | cpu = CPU; |
240 | if (t->flags & THREAD_FLAG_WIRED) { |
240 | if (t->flags & THREAD_FLAG_WIRED) { |
- | 241 | ASSERT(t->cpu != NULL); |
|
241 | cpu = t->cpu; |
242 | cpu = t->cpu; |
242 | } |
243 | } |
243 | t->state = Ready; |
244 | t->state = Ready; |
244 | spinlock_unlock(&t->lock); |
245 | spinlock_unlock(&t->lock); |
245 | 246 | ||
Line 494... | Line 495... | ||
494 | void thread_detach(thread_t *t) |
495 | void thread_detach(thread_t *t) |
495 | { |
496 | { |
496 | ipl_t ipl; |
497 | ipl_t ipl; |
497 | 498 | ||
498 | /* |
499 | /* |
499 | * Since the thread is expected to not be already detached, |
500 | * Since the thread is expected not to be already detached, |
500 | * pointer to it must be still valid. |
501 | * pointer to it must be still valid. |
501 | */ |
502 | */ |
502 | ipl = interrupts_disable(); |
503 | ipl = interrupts_disable(); |
503 | spinlock_lock(&t->lock); |
504 | spinlock_lock(&t->lock); |
504 | ASSERT(!t->detached); |
505 | ASSERT(!t->detached); |
Line 578... | Line 579... | ||
578 | 579 | ||
579 | uint64_t cycles; |
580 | uint64_t cycles; |
580 | char suffix; |
581 | char suffix; |
581 | order(t->cycles, &cycles, &suffix); |
582 | order(t->cycles, &cycles, &suffix); |
582 | 583 | ||
583 | printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx " |
584 | printf("%-6llu %-10s %#10zx %-8s %#10zx %-3ld %#10zx " |
584 | "%#10zx %9llu%c ", t->tid, t->name, t, |
585 | "%#10zx %9llu%c ", t->tid, t->name, t, |
585 | thread_states[t->state], t->task, t->task->context, |
586 | thread_states[t->state], t->task, t->task->context, |
586 | t->thread_code, t->kstack, cycles, suffix); |
587 | t->thread_code, t->kstack, cycles, suffix); |
587 | 588 | ||
588 | if (t->cpu) |
589 | if (t->cpu) |
Line 634... | Line 635... | ||
634 | } |
635 | } |
635 | 636 | ||
636 | /** Process syscall to create new thread. |
637 | /** Process syscall to create new thread. |
637 | * |
638 | * |
638 | */ |
639 | */ |
639 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name) |
640 | unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name, thread_id_t *uspace_thread_id) |
640 | { |
641 | { |
641 | thread_t *t; |
642 | thread_t *t; |
642 | char namebuf[THREAD_NAME_BUFLEN]; |
643 | char namebuf[THREAD_NAME_BUFLEN]; |
643 | uspace_arg_t *kernel_uarg; |
644 | uspace_arg_t *kernel_uarg; |
644 | uint32_t tid; |
- | |
645 | int rc; |
645 | int rc; |
646 | 646 | ||
647 | rc = copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN); |
647 | rc = copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN); |
648 | if (rc != 0) |
648 | if (rc != 0) |
649 | return (unative_t) rc; |
649 | return (unative_t) rc; |
Line 656... | Line 656... | ||
656 | } |
656 | } |
657 | 657 | ||
658 | t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, |
658 | t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, |
659 | false); |
659 | false); |
660 | if (t) { |
660 | if (t) { |
661 | tid = t->tid; |
- | |
662 | thread_ready(t); |
661 | thread_ready(t); |
- | 662 | if (uspace_thread_id != NULL) |
|
- | 663 | return (unative_t) copy_to_uspace(uspace_thread_id, &t->tid, |
|
663 | return (unative_t) tid; |
664 | sizeof(t->tid)); |
- | 665 | else |
|
- | 666 | return 0; |
|
664 | } else { |
667 | } else |
665 | free(kernel_uarg); |
668 | free(kernel_uarg); |
666 | } |
- | |
667 | 669 | ||
668 | return (unative_t) ENOMEM; |
670 | return (unative_t) ENOMEM; |
669 | } |
671 | } |
670 | 672 | ||
671 | /** Process syscall to terminate thread. |
673 | /** Process syscall to terminate thread. |
Line 676... | Line 678... | ||
676 | thread_exit(); |
678 | thread_exit(); |
677 | /* Unreachable */ |
679 | /* Unreachable */ |
678 | return 0; |
680 | return 0; |
679 | } |
681 | } |
680 | 682 | ||
- | 683 | /** Syscall for getting TID. |
|
- | 684 | * |
|
- | 685 | * @param uspace_thread_id Userspace address of 8-byte buffer where to store |
|
- | 686 | * current thread ID. |
|
681 | /** @} |
687 | * |
- | 688 | * @return 0 on success or an error code from @ref errno.h. |
|
682 | */ |
689 | */ |
- | 690 | unative_t sys_thread_get_id(thread_id_t *uspace_thread_id) |
|
- | 691 | { |
|
- | 692 | /* |
|
- | 693 | * No need to acquire lock on THREAD because tid |
|
- | 694 | * remains constant for the lifespan of the thread. |
|
- | 695 | */ |
|
- | 696 | return (unative_t) copy_to_uspace(uspace_thread_id, &THREAD->tid, |
|
- | 697 | sizeof(THREAD->tid)); |
|
- | 698 | } |
|
683 | 699 | ||
- | 700 | /** @} |
|
- | 701 | */ |