Browse Source

AP_HAL_Linux: split out a calculate_thread_priority method

zr-v5.1
Peter Barker 4 years ago committed by Andrew Tridgell
parent
commit
d0b3b926c0
  1. 26
      libraries/AP_HAL_Linux/Scheduler.cpp
  2. 4
      libraries/AP_HAL_Linux/Scheduler.h

26
libraries/AP_HAL_Linux/Scheduler.cpp

@ -348,16 +348,9 @@ void Scheduler::teardown() @@ -348,16 +348,9 @@ void Scheduler::teardown()
_uart_thread.join();
}
/*
create a new thread
*/
bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_t stack_size, priority_base base, int8_t priority)
// calculates an integer to be used as the priority for a newly-created thread
uint8_t Scheduler::calculate_thread_priority(priority_base base, int8_t priority) const
{
Thread *thread = new Thread{(Thread::task_t)proc};
if (!thread) {
return false;
}
uint8_t thread_priority = APM_LINUX_IO_PRIORITY;
static const struct {
priority_base base;
@ -382,6 +375,21 @@ bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_ @@ -382,6 +375,21 @@ bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_
}
}
return thread_priority;
}
/*
create a new thread
*/
bool Scheduler::thread_create(AP_HAL::MemberProc proc, const char *name, uint32_t stack_size, priority_base base, int8_t priority)
{
Thread *thread = new Thread{(Thread::task_t)proc};
if (!thread) {
return false;
}
const uint8_t thread_priority = calculate_thread_priority(base, priority);
// Add 256k to HAL-independent requested stack size
thread->set_stack_size(256 * 1024 + stack_size);

4
libraries/AP_HAL_Linux/Scheduler.h

@ -86,6 +86,10 @@ private: @@ -86,6 +86,10 @@ private:
AP_HAL::MemberProc _io_proc[LINUX_SCHEDULER_MAX_IO_PROCS];
uint8_t _num_io_procs;
// calculates an integer to be used as the priority for a
// newly-created thread
uint8_t calculate_thread_priority(priority_base base, int8_t priority) const;
SchedulerThread _timer_thread{FUNCTOR_BIND_MEMBER(&Scheduler::_timer_task, void), *this};
SchedulerThread _io_thread{FUNCTOR_BIND_MEMBER(&Scheduler::_io_task, void), *this};
SchedulerThread _rcin_thread{FUNCTOR_BIND_MEMBER(&Scheduler::_rcin_task, void), *this};

Loading…
Cancel
Save