Lines Matching full:t

95 static inline void posix_thread_q_set(struct posix_thread *t, enum posix_thread_qid qid)  in posix_thread_q_set()  argument
101 sys_dlist_append(&posix_thread_q[qid], &t->q_node); in posix_thread_q_set()
102 t->qid = qid; in posix_thread_q_set()
105 __ASSERT(false, "cannot set invalid qid %d for posix thread %p", qid, t); in posix_thread_q_set()
110 static inline enum posix_thread_qid posix_thread_q_get(struct posix_thread *t) in posix_thread_q_get() argument
112 switch (t->qid) { in posix_thread_q_get()
116 return t->qid; in posix_thread_q_get()
118 __ASSERT(false, "posix thread %p has invalid qid: %d", t, t->qid); in posix_thread_q_get()
131 static inline size_t posix_thread_to_offset(struct posix_thread *t) in posix_thread_to_offset() argument
133 return t - posix_thread_pool; in posix_thread_to_offset()
143 struct posix_thread *t; in to_posix_thread() local
158 t = &posix_thread_pool[bit]; in to_posix_thread()
165 actually_initialized = !(posix_thread_q_get(t) == POSIX_THREAD_READY_Q || in to_posix_thread()
166 (posix_thread_q_get(t) == POSIX_THREAD_DONE_Q && in to_posix_thread()
167 t->attr.detachstate == PTHREAD_CREATE_DETACHED)); in to_posix_thread()
180 struct posix_thread *t; in pthread_self() local
182 t = (struct posix_thread *)CONTAINER_OF(k_current_get(), struct posix_thread, thread); in pthread_self()
183 bit = posix_thread_to_offset(t); in pthread_self()
205 struct posix_thread *t = NULL; in __z_pthread_cleanup_push() local
209 t = to_posix_thread(pthread_self()); in __z_pthread_cleanup_push()
211 __ASSERT_NO_MSG(t != NULL); in __z_pthread_cleanup_push()
215 sys_slist_prepend(&t->cleanup_list, &c->node); in __z_pthread_cleanup_push()
223 struct posix_thread *t = NULL; in __z_pthread_cleanup_pop() local
226 t = to_posix_thread(pthread_self()); in __z_pthread_cleanup_pop()
227 __ASSERT_NO_MSG(t != NULL); in __z_pthread_cleanup_pop()
228 node = sys_slist_get(&t->cleanup_list); in __z_pthread_cleanup_pop()
464 static void posix_thread_finalize(struct posix_thread *t, void *retval) in posix_thread_finalize() argument
472 SYS_SLIST_FOR_EACH_NODE_SAFE(&t->key_list, node_l, node_s) { in posix_thread_finalize()
503 sys_dlist_remove(&t->q_node); in posix_thread_finalize()
504 posix_thread_q_set(t, POSIX_THREAD_DONE_Q); in posix_thread_finalize()
505 t->retval = retval; in posix_thread_finalize()
512 k_thread_abort(&t->thread); in posix_thread_finalize()
521 struct posix_thread *t = CONTAINER_OF(k_current_get(), struct posix_thread, thread); in zephyr_thread_wrapper() local
530 posix_thread_finalize(t, fun_ptr(arg1)); in zephyr_thread_wrapper()
537 struct posix_thread *t; in posix_thread_recycle() local
542 SYS_DLIST_FOR_EACH_CONTAINER_SAFE(&posix_thread_q[POSIX_THREAD_DONE_Q], t, safe_t, in posix_thread_recycle()
544 if (t->attr.detachstate == PTHREAD_CREATE_JOINABLE) { in posix_thread_recycle()
549 sys_dlist_remove(&t->q_node); in posix_thread_recycle()
550 sys_dlist_append(&recyclables, &t->q_node); in posix_thread_recycle()
560 SYS_DLIST_FOR_EACH_CONTAINER(&recyclables, t, q_node) { in posix_thread_recycle()
561 if (t->attr.caller_destroys) { in posix_thread_recycle()
562 t->attr = (struct posix_thread_attr){0}; in posix_thread_recycle()
564 (void)pthread_attr_destroy((pthread_attr_t *)&t->attr); in posix_thread_recycle()
570 t = CONTAINER_OF(sys_dlist_get(&recyclables), struct posix_thread, q_node); in posix_thread_recycle()
571 posix_thread_q_set(t, POSIX_THREAD_READY_Q); in posix_thread_recycle()
589 struct posix_thread *t = NULL; in pthread_create() local
600 t = CONTAINER_OF(sys_dlist_get(&posix_thread_q[POSIX_THREAD_READY_Q]), in pthread_create()
604 posix_thread_q_set(t, POSIX_THREAD_RUN_Q); in pthread_create()
605 sys_slist_init(&t->key_list); in pthread_create()
606 sys_slist_init(&t->cleanup_list); in pthread_create()
610 if (t != NULL && IS_ENABLED(CONFIG_PTHREAD_CREATE_BARRIER)) { in pthread_create()
615 sys_dlist_remove(&t->q_node); in pthread_create()
616 posix_thread_q_set(t, POSIX_THREAD_READY_Q); in pthread_create()
618 t = NULL; in pthread_create()
622 if (t == NULL) { in pthread_create()
629 err = pthread_attr_init((pthread_attr_t *)&t->attr); in pthread_create()
630 if (err == 0 && !__attr_is_runnable(&t->attr)) { in pthread_create()
631 (void)pthread_attr_destroy((pthread_attr_t *)&t->attr); in pthread_create()
637 sys_dlist_remove(&t->q_node); in pthread_create()
638 posix_thread_q_set(t, POSIX_THREAD_READY_Q); in pthread_create()
643 t->attr.caller_destroys = false; in pthread_create()
646 t->attr = *(struct posix_thread_attr *)_attr; in pthread_create()
649 if (t->attr.inheritsched == PTHREAD_INHERIT_SCHED) { in pthread_create()
652 t->attr.priority = in pthread_create()
654 t->attr.schedpolicy = pol; in pthread_create()
659 &t->thread, t->attr.stack, __get_attr_stacksize(&t->attr) + t->attr.guardsize, in pthread_create()
662 posix_to_zephyr_priority(t->attr.priority, t->attr.schedpolicy), 0, K_NO_WAIT); in pthread_create()
673 *th = mark_pthread_obj_initialized(posix_thread_to_offset(t)); in pthread_create()
675 LOG_DBG("Created pthread %p", &t->thread); in pthread_create()
717 struct posix_thread *t = NULL; in pthread_setcancelstate() local
726 t = to_posix_thread(pthread_self()); in pthread_setcancelstate()
727 if (t == NULL) { in pthread_setcancelstate()
733 *oldstate = t->attr.cancelstate; in pthread_setcancelstate()
736 t->attr.cancelstate = state; in pthread_setcancelstate()
737 cancel_pending = t->attr.cancelpending; in pthread_setcancelstate()
738 cancel_type = t->attr.canceltype; in pthread_setcancelstate()
745 posix_thread_finalize(t, PTHREAD_CANCELED); in pthread_setcancelstate()
759 struct posix_thread *t; in pthread_setcanceltype() local
767 t = to_posix_thread(pthread_self()); in pthread_setcanceltype()
768 if (t == NULL) { in pthread_setcanceltype()
774 *oldtype = t->attr.canceltype; in pthread_setcanceltype()
776 t->attr.canceltype = type; in pthread_setcanceltype()
792 struct posix_thread *t = NULL; in pthread_testcancel() local
795 t = to_posix_thread(pthread_self()); in pthread_testcancel()
796 if (t == NULL) { in pthread_testcancel()
799 if (t->attr.cancelstate != PTHREAD_CANCEL_ENABLE) { in pthread_testcancel()
802 if (t->attr.cancelpending) { in pthread_testcancel()
804 t->attr.cancelstate = PTHREAD_CANCEL_DISABLE; in pthread_testcancel()
809 posix_thread_finalize(t, PTHREAD_CANCELED); in pthread_testcancel()
823 struct posix_thread *t = NULL; in pthread_cancel() local
826 t = to_posix_thread(pthread); in pthread_cancel()
827 if (t == NULL) { in pthread_cancel()
832 if (!__attr_is_initialized(&t->attr)) { in pthread_cancel()
839 t->attr.cancelpending = true; in pthread_cancel()
840 cancel_state = t->attr.cancelstate; in pthread_cancel()
841 cancel_type = t->attr.canceltype; in pthread_cancel()
846 posix_thread_finalize(t, PTHREAD_CANCELED); in pthread_cancel()
861 struct posix_thread *t = NULL; in pthread_setschedparam() local
869 t = to_posix_thread(pthread); in pthread_setschedparam()
870 if (t == NULL) { in pthread_setschedparam()
880 k_thread_priority_set(&t->thread, new_prio); in pthread_setschedparam()
895 struct posix_thread *t = NULL; in pthread_setschedprio() local
910 t = to_posix_thread(thread); in pthread_setschedprio()
911 if (t == NULL) { in pthread_setschedprio()
921 k_thread_priority_set(&t->thread, new_prio); in pthread_setschedprio()
977 struct posix_thread *t; in pthread_getschedparam() local
984 t = to_posix_thread(pthread); in pthread_getschedparam()
985 if (t == NULL) { in pthread_getschedparam()
990 if (!__attr_is_initialized(&t->attr)) { in pthread_getschedparam()
997 zephyr_to_posix_priority(k_thread_priority_get(&t->thread), policy); in pthread_getschedparam()
1068 struct posix_thread *t = NULL; in pthread_timedjoin_internal() local
1076 t = to_posix_thread(pthread); in pthread_timedjoin_internal()
1077 if (t == NULL) { in pthread_timedjoin_internal()
1082 LOG_DBG("Pthread %p joining..", &t->thread); in pthread_timedjoin_internal()
1084 if (t->attr.detachstate != PTHREAD_CREATE_JOINABLE) { in pthread_timedjoin_internal()
1090 if (posix_thread_q_get(t) == POSIX_THREAD_READY_Q) { in pthread_timedjoin_internal()
1100 t->attr.detachstate = PTHREAD_CREATE_DETACHED; in pthread_timedjoin_internal()
1105 LOG_DBG("Pthread %p has already been joined", &t->thread); in pthread_timedjoin_internal()
1108 LOG_DBG("Pthread %p is not a joinable", &t->thread); in pthread_timedjoin_internal()
1114 ret = k_thread_join(&t->thread, timeout); in pthread_timedjoin_internal()
1118 t->attr.detachstate = PTHREAD_CREATE_JOINABLE; in pthread_timedjoin_internal()
1129 LOG_DBG("Joined pthread %p", &t->thread); in pthread_timedjoin_internal()
1133 *status = t->retval; in pthread_timedjoin_internal()
1187 struct posix_thread *t = NULL; in pthread_detach() local
1190 t = to_posix_thread(pthread); in pthread_detach()
1191 if (t == NULL) { in pthread_detach()
1196 if (posix_thread_q_get(t) == POSIX_THREAD_READY_Q || in pthread_detach()
1197 t->attr.detachstate != PTHREAD_CREATE_JOINABLE) { in pthread_detach()
1198 LOG_DBG("Pthread %p cannot be detached", &t->thread); in pthread_detach()
1204 t->attr.detachstate = PTHREAD_CREATE_DETACHED; in pthread_detach()
1208 LOG_DBG("Pthread %p detached", &t->thread); in pthread_detach()
1497 struct posix_thread *t = NULL; in pthread_sigmask() local
1504 t = to_posix_thread(pthread_self()); in pthread_sigmask()
1505 if (t == NULL) { in pthread_sigmask()
1511 *oset = t->sigset; in pthread_sigmask()
1522 t->sigset.sig[i] |= set->sig[i]; in pthread_sigmask()
1526 t->sigset = *set; in pthread_sigmask()
1530 t->sigset.sig[i] &= ~set->sig[i]; in pthread_sigmask()