20 #include <sys/types.h> 30 #define STACK_POISON 0xBEBACAFE 71 static inline void *
align_to(
void *p,
size_t align)
73 return (
void *)(((uintptr_t)p + align - 1) & ~(align - 1));
79 size_t stack_size, guard_size;
81 uint32_t *p, *curr, *begin, *
end;
83 if (pthread_getattr_np(
_ctx, &attr) != 0 ||
84 pthread_attr_getstack(&attr, &stackp, &stack_size) != 0 ||
85 pthread_attr_getguardsize(&attr, &guard_size) != 0) {
89 stack_size /=
sizeof(uint32_t);
90 guard_size /=
sizeof(uint32_t);
94 end = (uint32_t *)stackp;
95 begin = end + stack_size;
96 curr = (uint32_t *)
align_to(alloca(
sizeof(uint32_t)),
alignof(uint32_t));
103 if (abs(curr - begin) > abs(curr - end)) {
107 for (p = end; p > curr; p--) {
117 for (p = end; p < curr; p++) {
161 struct sched_param param = { .sched_priority = prio };
165 pthread_attr_init(&attr);
172 if (geteuid() == 0) {
173 if ((r = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) != 0 ||
174 (r = pthread_attr_setschedpolicy(&attr, policy)) != 0 ||
175 (r = pthread_attr_setschedparam(&attr, ¶m)) != 0) {
176 AP_HAL::panic(
"Failed to set attributes for thread '%s': %s",
182 if (pthread_attr_setstacksize(&attr,
_stack_size) != 0) {
192 pthread_attr_destroy(&attr);
195 pthread_setname_np(
_ctx, name);
205 return pthread_equal(pthread_self(),
_ctx);
216 if (pthread_join(
_ctx, &ret) != 0 ||
217 (intptr_t)ret != 0) {
249 if (_period_usec == 0) {
257 if (dt > _period_usec) {
263 next_run_usec += _period_usec;
void microsleep(uint32_t usec)
char * strerror(int errnum)
POSIX strerror() - convert POSIX errno to text with user message.
static Scheduler * from(AP_HAL::Scheduler *scheduler)
static void swap(float &a, float &b)
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
struct Linux::Thread::stack_debug _stack_debug
bool set_rate(uint32_t rate_hz)
static void * align_to(void *p, size_t align)
static void * _run_trampoline(void *arg)
bool set_stack_size(size_t stack_size)
bool start(const char *name, int policy, int prio)
void panic(const char *errormsg,...) FMT_PRINTF(1
uint32_t hz_to_usec(uint32_t freq)
AP_HAL::Scheduler * scheduler