20 std::atomic<bool> PosixTask::s_permissions_reported(
false);
23 typedef void* (*pthread_func_ptr)(
void*);
28 wrapper.
run(&wrapper);
36 long page_size = sysconf(_SC_PAGESIZE);
39 "[WARNING] %s could not determine page size %s. Skipping stack-size check.\n",
44 else if ((stack %
static_cast<FwSizeType>(page_size)) != 0) {
58 if (stack <=
static_cast<FwSizeType>(PTHREAD_STACK_MIN)) {
65 stack =
static_cast<FwSizeType>(PTHREAD_STACK_MIN);
67 status = pthread_attr_setstacksize(&attributes,
static_cast<size_t>(stack));
77 if (priority < min_priority) {
82 priority = min_priority;
85 else if (priority > max_priority) {
90 priority = max_priority;
94 status = pthread_attr_setschedpolicy(&attributes,
SCHED_POLICY);
96 status = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);
99 sched_param schedParam;
100 memset(&schedParam, 0,
sizeof(sched_param));
102 status = pthread_attr_setschedparam(&attributes, &schedParam);
117 status = pthread_attr_setaffinity_np(&attributes,
sizeof(cpu_set_t), &cpu_set);
120 Fw::Logger::logMsg(
"[WARNING] %s setting CPU affinity is only available with GNU pthreads\n",
128 PosixTaskHandle& handle = this->m_handle;
131 pthread_attr_t attributes;
132 memset(&attributes, 0,
sizeof(attributes));
133 pthread_status = pthread_attr_init(&attributes);
149 handle.m_is_valid =
true;
152 (void) pthread_attr_destroy(&attributes);
162 Os::Task::Status status = this->create(arguments, PermissionExpectation::EXPECT_PERMISSION);
164 if (status == Os::Task::Status::ERROR_PERMISSION) {
165 if (not PosixTask::s_permissions_reported) {
169 Fw::Logger::logMsg(
"[NOTE] You have insufficient permissions to create a task with priority and/or cpu affinity.\n");
173 Fw::Logger::logMsg(
"[NOTE] 1. Use tasks without priority and affinity using parameterless start()\n");
174 Fw::Logger::logMsg(
"[NOTE] 2. Run this executable as a user with task priority permission\n");
175 Fw::Logger::logMsg(
"[NOTE] 3. Grant capability with \"setcap 'cap_sys_nice=eip'\" or equivalent\n");
177 PosixTask::s_permissions_reported =
true;
180 status = this->create(arguments, PermissionExpectation::EXPECT_NO_PERMISSION);
191 status = Os::Task::Status::INVALID_HANDLE;
200 return &this->m_handle;
uint8_t PlatformPointerCastType
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSizeType FwSizeType
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)
void suspend(SuspensionType suspensionType) override
suspend the task given the suspension type
PermissionExpectation
Enumeration of permission expectations.
@ EXPECT_PERMISSION
Expect that you hold necessary permissions.
Status join() override
block until the task has ended
void resume() override
resume a suspended task
TaskHandle * getHandle() override
return the underlying task handle (implementation specific)
void onStart() override
perform required task start actions
Status start(const Arguments &arguments) override
start the task
Wrapper for task routine that ensures onStart() is called once the task actually begins.
static void run(void *task_pointer)
run the task routine wrapper
Task handle representation.
void * m_routine_argument
const Os::TaskString m_name
static constexpr FwSizeType TASK_DEFAULT
const char * toChar() const
@ OP_OK
Operation was successful.
PlatformIntType set_priority_params(pthread_attr_t &attributes, const Os::Task::Arguments &arguments)
void * pthread_entry_wrapper(void *wrapper_pointer)
PlatformIntType set_cpu_affinity(pthread_attr_t &attributes, const Os::Task::Arguments &arguments)
PlatformIntType set_stack_size(pthread_attr_t &attributes, const Os::Task::Arguments &arguments)
static const PlatformIntType SCHED_POLICY
Task::Status posix_status_to_task_status(PlatformIntType posix_status)
static constexpr PlatformIntType SUCCESS
pthread_t m_task_descriptor
Posix task descriptor.
bool m_is_valid
Is the above descriptor valid.