Lines Matching +full:- +full:t
5 * SPDX-License-Identifier: Apache-2.0
24 (((_zprio) < 0) ? (-1 * ((_zprio) + 1)) : (CONFIG_NUM_PREEMPT_PRIORITIES - (_zprio)-1))
27 (((_pol) == SCHED_FIFO) ? (-1 * ((_prio) + 1)) \
28 : (CONFIG_NUM_PREEMPT_PRIORITIES - (_prio)-1))
47 return attr->stacksize + 1; in __get_attr_stacksize()
52 attr->stacksize = stacksize - 1; in __set_attr_stacksize()
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()
232 __ASSERT_NO_MSG(c->routine != NULL); in __z_pthread_cleanup_pop()
235 c->routine(c->arg); in __z_pthread_cleanup_pop()
251 /* Non-static so that they can be tested in ztest */
257 __ASSERT_NO_MSG(-z_prio <= CONFIG_NUM_COOP_PRIORITIES); in zephyr_to_posix_priority()
269 /* Non-static so that they can be tested in ztest */
281 if (attr == NULL || attr->stack == NULL) { in __attr_is_runnable()
294 if (!valid_posix_policy(attr->schedpolicy)) { in __attr_is_runnable()
295 LOG_DBG("Invalid scheduler policy %d", attr->schedpolicy); in __attr_is_runnable()
308 if (attr == NULL || !attr->initialized) { in __attr_is_initialized()
326 !is_posix_policy_prio_valid(schedparam->sched_priority, attr->schedpolicy)) { in pthread_attr_setschedparam()
331 attr->priority = schedparam->sched_priority; in pthread_attr_setschedparam()
356 if (attr->stack != NULL) { in pthread_attr_setstack()
357 ret = k_thread_stack_free(attr->stack); in pthread_attr_setstack()
360 __get_attr_stacksize(attr), attr->stack); in pthread_attr_setstack()
364 attr->stack = stackaddr; in pthread_attr_setstack()
367 LOG_DBG("Assigned thread stack %zu@%p to attr %p", __get_attr_stacksize(attr), attr->stack, in pthread_attr_setstack()
385 *contentionscope = attr->contentionscope; in pthread_attr_getscope()
412 attr->contentionscope = contentionscope; in pthread_attr_setscope()
428 *inheritsched = attr->inheritsched; in pthread_attr_getinheritsched()
451 attr->inheritsched = inheritsched; in pthread_attr_setinheritsched()
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()
475 key_obj = thread_spec_data->key; in posix_thread_finalize()
476 if (key_obj->destructor != NULL) { in posix_thread_finalize()
477 (key_obj->destructor)(thread_spec_data->spec_data); in posix_thread_finalize()
482 &key_obj->key_data_l, in posix_thread_finalize()
486 if (&key_data->thread_data == thread_spec_data) { in posix_thread_finalize()
488 &key_obj->key_data_l, 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()
645 /* copy user-provided attr into thread, caller must destroy attr at a later time */ 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
718 bool cancel_type = -1; in pthread_setcancelstate()
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
864 !is_posix_policy_prio_valid(param->sched_priority, policy)) { in pthread_setschedparam()
869 t = to_posix_thread(pthread); in pthread_setschedparam()
870 if (t == NULL) { in pthread_setschedparam()
876 new_prio = posix_to_zephyr_priority(param->sched_priority, policy); 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
896 int policy = -1; in pthread_setschedprio()
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()
944 attr->guardsize = CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT; in pthread_attr_init()
945 attr->contentionscope = PTHREAD_SCOPE_SYSTEM; in pthread_attr_init()
946 attr->inheritsched = PTHREAD_INHERIT_SCHED; in pthread_attr_init()
949 attr->stack = k_thread_stack_alloc(DYNAMIC_STACK_SIZE + attr->guardsize, in pthread_attr_init()
951 if (attr->stack == NULL) { in pthread_attr_init()
952 LOG_DBG("Did not auto-allocate thread stack"); in pthread_attr_init()
957 attr->stack); in pthread_attr_init()
962 attr->initialized = true; in pthread_attr_init()
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()
996 param->sched_priority = in pthread_getschedparam()
997 zephyr_to_posix_priority(k_thread_priority_get(&t->thread), policy); in pthread_getschedparam()
1019 if (!_once->flag) { in pthread_once()
1021 _once->flag = true; in pthread_once()
1050 self->attr.cancelstate = PTHREAD_CANCEL_ENABLE; in pthread_exit()
1055 LOG_DBG("Aborting non-pthread %p", k_current_get()); in pthread_exit()
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()
1121 if (ret == -EBUSY) { in pthread_timedjoin_internal()
1123 } else if (ret == -EAGAIN) { in pthread_timedjoin_internal()
1126 /* Can only be ok or -EDEADLK, which should never occur for pthreads */ in pthread_timedjoin_internal()
1129 LOG_DBG("Joined pthread %p", &t->thread); in pthread_timedjoin_internal()
1133 *status = t->retval; in pthread_timedjoin_internal()
1144 * Non-portable GNU extension of IEEE 1003.1
1152 if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= NSEC_PER_SEC) { in pthread_timedjoin_np()
1162 * Non-portable GNU extension of IEEE 1003.1
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()
1227 *detachstate = attr->detachstate; in pthread_attr_getdetachstate()
1245 attr->detachstate = detachstate; in pthread_attr_setdetachstate()
1262 *policy = attr->schedpolicy; in pthread_attr_getschedpolicy()
1279 attr->schedpolicy = policy; in pthread_attr_setschedpolicy()
1321 k_thread_stack_alloc(stacksize + attr->guardsize, k_is_user_context() ? K_USER : 0); in pthread_attr_setstacksize()
1329 __get_attr_stacksize(attr) + attr->guardsize); in pthread_attr_setstacksize()
1332 LOG_DBG("Allocated thread stack %zu@%p", stacksize + attr->guardsize, new_stack); in pthread_attr_setstacksize()
1334 if (attr->stack != NULL) { in pthread_attr_setstacksize()
1335 ret = k_thread_stack_free(attr->stack); in pthread_attr_setstacksize()
1338 __get_attr_stacksize(attr), attr->stack); in pthread_attr_setstacksize()
1343 attr->stack = new_stack; in pthread_attr_setstacksize()
1361 *stackaddr = attr->stack; in pthread_attr_getstack()
1374 *guardsize = attr->guardsize; in pthread_attr_getguardsize()
1387 attr->guardsize = guardsize; in pthread_attr_setguardsize()
1405 schedparam->sched_priority = attr->priority; in pthread_attr_getschedparam()
1423 ret = k_thread_stack_free(attr->stack); in pthread_attr_destroy()
1426 attr->stack); in pthread_attr_destroy()
1475 return k_thread_name_copy(kthread, name, len - 1); in pthread_getname_np()
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()
1521 for (size_t i = 0; i < ARRAY_SIZE(set->sig); ++i) { in pthread_sigmask()
1522 t->sigset.sig[i] |= set->sig[i]; in pthread_sigmask()
1526 t->sigset = *set; in pthread_sigmask()
1529 for (size_t i = 0; i < ARRAY_SIZE(set->sig); ++i) { in pthread_sigmask()
1530 t->sigset.sig[i] &= ~set->sig[i]; in pthread_sigmask()