updated fixed timeslot task

This commit is contained in:
Robin Müller 2021-03-23 14:45:33 +01:00
parent d781c6fcec
commit aaceac81af
2 changed files with 9 additions and 31 deletions

View File

@ -1,9 +1,8 @@
#include "taskHelpers.h"
#include "../../osal/host/FixedTimeslotTask.h" #include "../../osal/host/FixedTimeslotTask.h"
#include "../../ipc/MutexFactory.h" #include "../../ipc/MutexFactory.h"
#include "../../osal/host/Mutex.h" #include "../../osal/host/Mutex.h"
#include "../../osal/host/FixedTimeslotTask.h" #include "../../osal/host/FixedTimeslotTask.h"
#include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../tasks/ExecutableObjectIF.h" #include "../../tasks/ExecutableObjectIF.h"
@ -12,6 +11,7 @@
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
#include "../windows/winTaskHelpers.h"
#elif defined(LINUX) #elif defined(LINUX)
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -24,34 +24,12 @@ FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
// It is propably possible to set task priorities by using the native // It is propably possible to set task priorities by using the native
// task handles for Windows / Linux // task handles for Windows / Linux
mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this); mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this);
#if defined(WIN32) #if defined(_WIN32)
/* List of possible priority classes: tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
* https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/ #elif defined(__unix__)
* nf-processthreadsapi-setpriorityclass // TODO: We could reuse existing code here.
* And respective thread priority numbers:
* https://docs.microsoft.com/en-us/windows/
* win32/procthread/scheduling-priorities */
int result = SetPriorityClass(
reinterpret_cast<HANDLE>(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<HANDLE>(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.
#endif #endif
tasks::insertTaskName(mainThread.get_id(), taskName);
} }
FixedTimeslotTask::~FixedTimeslotTask(void) { FixedTimeslotTask::~FixedTimeslotTask(void) {

View File

@ -12,7 +12,7 @@
#if defined(WIN32) #if defined(WIN32)
#include <processthreadsapi.h> #include <processthreadsapi.h>
#include <fsfw/osal/windows/winTaskHelpers.h> #include <fsfw/osal/windows/winTaskHelpers.h>
#elif defined(LINUX) #elif defined(__unix__)
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -26,10 +26,10 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this); mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
#if defined(_WIN32) #if defined(_WIN32)
tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority); tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
tasks::insertTaskName(mainThread.get_id(), taskName);
#elif defined(__unix__) #elif defined(__unix__)
// TODO: We could reuse existing code here. // TODO: We could reuse existing code here.
#endif #endif
tasks::insertTaskName(mainThread.get_id(), taskName);
} }
PeriodicTask::~PeriodicTask(void) { PeriodicTask::~PeriodicTask(void) {