create a new thread */
| 407 | create a new thread |
| 408 | */ |
| 409 | bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_t stack_size, priority_base base, int8_t priority) |
| 410 | { |
| 411 | Thread *thread = NEW_NOTHROW Thread{(Thread::task_t)proc}; |
| 412 | if (!thread) { |
| 413 | return false; |
| 414 | } |
| 415 | |
| 416 | const uint8_t thread_priority = calculate_thread_priority(base, priority); |
| 417 | |
| 418 | // Add 256k to HAL-independent requested stack size |
| 419 | thread->set_stack_size(256 * 1024 + stack_size); |
| 420 | |
| 421 | /* |
| 422 | * We should probably store the thread handlers and join() when exiting, |
| 423 | * but let's the thread manage itself for now. |
| 424 | */ |
| 425 | thread->set_auto_free(true); |
| 426 | |
| 427 | if (!thread->start(name, SCHED_FIFO, thread_priority)) { |
| 428 | delete thread; |
| 429 | return false; |
| 430 | } |
| 431 | |
| 432 | return true; |
| 433 | } |
no test coverage detected