From db4587bb59603bdc83e6720193fd1782649a0678 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 23 Mar 2023 18:29:17 +0100 Subject: [PATCH] allow creating regular threads --- src/fsfw/osal/linux/PosixThread.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/fsfw/osal/linux/PosixThread.cpp b/src/fsfw/osal/linux/PosixThread.cpp index 9851876d..e90070bb 100644 --- a/src/fsfw/osal/linux/PosixThread.cpp +++ b/src/fsfw/osal/linux/PosixThread.cpp @@ -178,20 +178,32 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) { #ifndef FSFW_USE_REALTIME_FOR_LINUX #error "Please define FSFW_USE_REALTIME_FOR_LINUX with either 0 or 1" #endif + if (priority < 100) { + // RR -> This needs root privileges for the process #if FSFW_USE_REALTIME_FOR_LINUX == 1 - // RR -> This needs root privileges for the process - status = pthread_attr_setschedpolicy(&attributes, SCHED_RR); - if (status != 0) { - utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setschedpolicy"); + status = pthread_attr_setschedpolicy(&attributes, SCHED_RR); + if (status != 0) { + utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setschedpolicy"); + } +#else +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning + << "Real time priorities are only allowed if FSFW_USE_REALTIME_FOR_LINUX is set to 1" + << std::endl; +#endif +#endif + } else { + priority = 0; } sched_param scheduleParams; scheduleParams.__sched_priority = priority; status = pthread_attr_setschedparam(&attributes, &scheduleParams); if (status != 0) { - utility::printUnixErrorGeneric(CLASS_NAME, "createTask", "pthread_attr_setschedparam"); - } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "PosixThread: Setting priority failed" << std::endl; #endif + } // Set Signal Mask for suspend until startTask is called sigset_t waitSignal; sigemptyset(&waitSignal);