| 181 | ****************************************************************************/ |
| 182 | |
| 183 | int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, |
| 184 | FAR const pthread_attr_t *attr, |
| 185 | pthread_startroutine_t entry, pthread_addr_t arg) |
| 186 | { |
| 187 | pthread_attr_t default_attr = g_default_pthread_attr; |
| 188 | FAR struct tcb_s *ptcb; |
| 189 | struct sched_param param; |
| 190 | FAR struct tcb_s *parent; |
| 191 | int policy; |
| 192 | int errcode; |
| 193 | int ret; |
| 194 | |
| 195 | DEBUGASSERT(trampoline != NULL); |
| 196 | |
| 197 | parent = this_task(); |
| 198 | DEBUGASSERT(parent != NULL); |
| 199 | |
| 200 | /* If attributes were not supplied, use the default attributes */ |
| 201 | |
| 202 | if (!attr) |
| 203 | { |
| 204 | /* Inherit parent priority by default. except idle */ |
| 205 | |
| 206 | if (!is_idle_task(parent)) |
| 207 | { |
| 208 | default_attr.priority = parent->sched_priority; |
| 209 | } |
| 210 | |
| 211 | attr = &default_attr; |
| 212 | } |
| 213 | |
| 214 | /* Allocate a TCB for the new task. */ |
| 215 | |
| 216 | ptcb = kmm_zalloc(sizeof(struct tcb_s) + sizeof(struct pthread_entry_s)); |
| 217 | if (!ptcb) |
| 218 | { |
| 219 | serr("ERROR: Failed to allocate TCB\n"); |
| 220 | return ENOMEM; |
| 221 | } |
| 222 | |
| 223 | ptcb->flags |= TCB_FLAG_FREE_TCB; |
| 224 | |
| 225 | /* Initialize the task join */ |
| 226 | |
| 227 | nxtask_joininit(ptcb); |
| 228 | |
| 229 | /* Bind the parent's group to the new TCB (we have not yet joined the |
| 230 | * group). |
| 231 | */ |
| 232 | |
| 233 | group_bind(ptcb); |
| 234 | |
| 235 | #ifdef CONFIG_ARCH_ADDRENV |
| 236 | /* Share the address environment of the parent task group. */ |
| 237 | |
| 238 | ret = addrenv_join(this_task(), ptcb); |
| 239 | if (ret < 0) |
| 240 | { |
no test coverage detected