From aaceac81af9061892e8d25e66dec9bf963a21d65 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 23 Mar 2021 14:45:33 +0100 Subject: [PATCH] updated fixed timeslot task --- osal/host/FixedTimeslotTask.cpp | 36 +++++++-------------------------- osal/host/PeriodicTask.cpp | 4 ++-- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/osal/host/FixedTimeslotTask.cpp b/osal/host/FixedTimeslotTask.cpp index 272d99b9..3b169b5a 100644 --- a/osal/host/FixedTimeslotTask.cpp +++ b/osal/host/FixedTimeslotTask.cpp @@ -1,9 +1,8 @@ +#include "taskHelpers.h" #include "../../osal/host/FixedTimeslotTask.h" - #include "../../ipc/MutexFactory.h" #include "../../osal/host/Mutex.h" #include "../../osal/host/FixedTimeslotTask.h" - #include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../tasks/ExecutableObjectIF.h" @@ -12,6 +11,7 @@ #if defined(WIN32) #include +#include "../windows/winTaskHelpers.h" #elif defined(LINUX) #include #endif @@ -24,34 +24,12 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority, // It is propably possible to set task priorities by using the native // task handles for Windows / Linux mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this); -#if defined(WIN32) - /* List of possible priority classes: - * https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/ - * nf-processthreadsapi-setpriorityclass - * And respective thread priority numbers: - * https://docs.microsoft.com/en-us/windows/ - * win32/procthread/scheduling-priorities */ - int result = SetPriorityClass( - reinterpret_cast(mainThread.native_handle()), - ABOVE_NORMAL_PRIORITY_CLASS); - if(result != 0) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code " - << GetLastError() << std::endl; -#endif - } - result = SetThreadPriority( - reinterpret_cast(mainThread.native_handle()), - THREAD_PRIORITY_NORMAL); - if(result != 0) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code " - << GetLastError() << std::endl; -#endif - } -#elif defined(LINUX) - // TODO: we can just copy and paste the code from the linux OSAL here. +#if defined(_WIN32) + tasks::setTaskPriority(reinterpret_cast(mainThread.native_handle()), setPriority); +#elif defined(__unix__) + // TODO: We could reuse existing code here. #endif + tasks::insertTaskName(mainThread.get_id(), taskName); } FixedTimeslotTask::~FixedTimeslotTask(void) { diff --git a/osal/host/PeriodicTask.cpp b/osal/host/PeriodicTask.cpp index 4a02ee0d..d7abf9d0 100644 --- a/osal/host/PeriodicTask.cpp +++ b/osal/host/PeriodicTask.cpp @@ -12,7 +12,7 @@ #if defined(WIN32) #include #include -#elif defined(LINUX) +#elif defined(__unix__) #include #endif @@ -26,10 +26,10 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority, mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this); #if defined(_WIN32) tasks::setTaskPriority(reinterpret_cast(mainThread.native_handle()), setPriority); - tasks::insertTaskName(mainThread.get_id(), taskName); #elif defined(__unix__) // TODO: We could reuse existing code here. #endif + tasks::insertTaskName(mainThread.get_id(), taskName); } PeriodicTask::~PeriodicTask(void) {