20 std::atomic<bool> PosixTask::s_permissions_reported(
false);
23 typedef void* (*pthread_func_ptr)(
void*);
28 wrapper.
run(&wrapper);
38 long page_size = sysconf(_SC_PAGESIZE);
44 "[WARNING] %s could not determine page size %s. Skipping stack-size check.\n",
49 else if ((stack %
static_cast<FwSizeType>(page_size)) != 0) {
63 if (stack <=
static_cast<FwSizeType>(PTHREAD_STACK_MIN)) {
70 stack =
static_cast<FwSizeType>(PTHREAD_STACK_MIN);
72 status = pthread_attr_setstacksize(&attributes,
static_cast<size_t>(stack));
82 if (priority < min_priority) {
87 priority = min_priority;
90 else if (priority > max_priority) {
95 priority = max_priority;
99 status = pthread_attr_setschedpolicy(&attributes,
SCHED_POLICY);
101 status = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);
104 sched_param schedParam;
105 memset(&schedParam, 0,
sizeof(sched_param));
107 status = pthread_attr_setschedparam(&attributes, &schedParam);
122 status = pthread_attr_setaffinity_np(&attributes,
sizeof(cpu_set_t), &cpu_set);
125 Fw::Logger::log(
"[WARNING] %s setting CPU affinity is only available with GNU pthreads\n",
133 PosixTaskHandle& handle = this->m_handle;
136 pthread_attr_t attributes;
137 memset(&attributes, 0,
sizeof(attributes));
138 pthread_status = pthread_attr_init(&attributes);
154 handle.m_is_valid =
true;
157 (void) pthread_attr_destroy(&attributes);
167 Os::Task::Status status = this->create(arguments, PermissionExpectation::EXPECT_PERMISSION);
169 if (status == Os::Task::Status::ERROR_PERMISSION) {
170 if (not PosixTask::s_permissions_reported) {
174 Fw::Logger::log(
"[NOTE] You have insufficient permissions to create a task with priority and/or cpu affinity.\n");
175 Fw::Logger::log(
"[NOTE] A task without priority and affinity will be created.\n");
178 Fw::Logger::log(
"[NOTE] 1. Use tasks without priority and affinity using parameterless start()\n");
179 Fw::Logger::log(
"[NOTE] 2. Run this executable as a user with task priority permission\n");
180 Fw::Logger::log(
"[NOTE] 3. Grant capability with \"setcap 'cap_sys_nice=eip'\" or equivalent\n");
182 PosixTask::s_permissions_reported =
true;
185 status = this->create(arguments, PermissionExpectation::EXPECT_NO_PERMISSION);
196 status = Os::Task::Status::INVALID_HANDLE;
205 return &this->m_handle;
221 timespec sleep_interval;
222 sleep_interval.tv_sec = interval.
getSeconds();
223 sleep_interval.tv_nsec = interval.
getUSeconds() * 1000;
225 timespec remaining_interval;
226 remaining_interval.tv_sec = 0;
227 remaining_interval.tv_nsec = 0;
230 PlatformIntType status = nanosleep(&sleep_interval, &remaining_interval);
236 else if (EINTR == errno) {
237 sleep_interval = remaining_interval;
242 task_status = Os::Task::Status::DELAY_ERROR;
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSizeType FwSizeType
static void log(const char *format,...)
log a formated string with supplied arguments
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 _delay(Fw::TimeInterval interval) override
delay the current task
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
@ OP_OK
message sent/received okay
const char * toChar() const
@ OP_OK
Operation succeeded.
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.