name storage abstraction available for linux as well
This commit is contained in:
parent
bdd9889718
commit
d781c6fcec
@ -10,6 +10,7 @@ target_sources(${LIB_FSFW_NAME}
|
||||
QueueMapManager.cpp
|
||||
SemaphoreFactory.cpp
|
||||
TaskFactory.cpp
|
||||
taskHelpers.cpp
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Mutex.h"
|
||||
#include "PeriodicTask.h"
|
||||
#include "taskHelpers.h"
|
||||
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "taskHelpers.h"
|
||||
#include "../../tasks/TaskFactory.h"
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
#include "../../osal/host/PeriodicTask.h"
|
||||
@ -5,12 +6,6 @@
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "../windows/winTaskHelpers.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
|
||||
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
||||
@ -56,33 +51,12 @@ ReturnValue_t TaskFactory::delayTask(uint32_t delayMs){
|
||||
}
|
||||
|
||||
void TaskFactory::printMissedDeadline() {
|
||||
#ifdef __unix__
|
||||
char name[20] = {0};
|
||||
int status = pthread_getname_np(pthread_self(), name, sizeof(name));
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
if(status == 0) {
|
||||
sif::warning << "TaskFactory::printMissedDeadline: " << name << "" << std::endl;
|
||||
}
|
||||
else {
|
||||
sif::warning << "TaskFactory::printMissedDeadline: Unknown task name" << status <<
|
||||
std::endl;
|
||||
}
|
||||
#else
|
||||
if(status == 0) {
|
||||
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
|
||||
}
|
||||
else {
|
||||
sif::printWarning("TaskFactory::printMissedDeadline: Unknown task name\n", name);
|
||||
}
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#elif defined(_WIN32)
|
||||
std::string name = tasks::getTaskName(std::this_thread::get_id());
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TaskFactory::printMissedDeadline: " << name << std::endl;
|
||||
#else
|
||||
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* defined(_WIN32) */
|
||||
}
|
||||
|
||||
|
||||
|
27
osal/host/taskHelpers.cpp
Normal file
27
osal/host/taskHelpers.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "taskHelpers.h"
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
std::mutex nameMapLock;
|
||||
std::map<std::thread::id, std::string> taskNameMap;
|
||||
|
||||
ReturnValue_t tasks::insertTaskName(std::thread::id threadId, std::string taskName) {
|
||||
std::lock_guard<std::mutex> lg(nameMapLock);
|
||||
auto returnPair = taskNameMap.emplace(threadId, taskName);
|
||||
if(not returnPair.second) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
std::string tasks::getTaskName(std::thread::id threadId) {
|
||||
std::lock_guard<std::mutex> lg(nameMapLock);
|
||||
auto resultIter = taskNameMap.find(threadId);
|
||||
if(resultIter != taskNameMap.end()) {
|
||||
return resultIter->second;
|
||||
}
|
||||
else {
|
||||
return "Unknown task";
|
||||
}
|
||||
}
|
||||
|
16
osal/host/taskHelpers.h
Normal file
16
osal/host/taskHelpers.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FSFW_OSAL_HOST_TASKHELPERS_H_
|
||||
#define FSFW_OSAL_HOST_TASKHELPERS_H_
|
||||
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <thread>
|
||||
|
||||
namespace tasks {
|
||||
|
||||
ReturnValue_t insertTaskName(std::thread::id threadId, std::string taskName);
|
||||
std::string getTaskName(std::thread::id threadId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_OSAL_HOST_TASKHELPERS_H_ */
|
@ -1,9 +1,6 @@
|
||||
#include <fsfw/osal/windows/winTaskHelpers.h>
|
||||
#include <mutex>
|
||||
|
||||
std::mutex nameMapLock;
|
||||
std::map<std::thread::id, std::string> taskNameMap;
|
||||
|
||||
TaskPriority tasks::makeWinPriority(PriorityClass prioClass, PriorityNumber prioNumber) {
|
||||
return (static_cast<uint16_t>(prioClass) << 16) | static_cast<uint16_t> (prioNumber);
|
||||
}
|
||||
@ -108,23 +105,3 @@ ReturnValue_t tasks::setTaskPriority(HANDLE nativeHandle, TaskPriority priority)
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t tasks::insertTaskName(std::thread::id threadId, std::string taskName) {
|
||||
std::lock_guard<std::mutex> lg(nameMapLock);
|
||||
auto returnPair = taskNameMap.emplace(threadId, taskName);
|
||||
if(not returnPair.second) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
std::string tasks::getTaskName(std::thread::id threadId) {
|
||||
std::lock_guard<std::mutex> lg(nameMapLock);
|
||||
auto resultIter = taskNameMap.find(threadId);
|
||||
if(resultIter != taskNameMap.end()) {
|
||||
return resultIter->second;
|
||||
}
|
||||
else {
|
||||
return "Unknown task";
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,6 @@ void getWinPriorityParameters(TaskPriority priority, DWORD& priorityClass,
|
||||
|
||||
ReturnValue_t setTaskPriority(HANDLE nativeHandle, TaskPriority priority);
|
||||
|
||||
ReturnValue_t insertTaskName(std::thread::id threadId, std::string taskName);
|
||||
std::string getTaskName(std::thread::id threadId);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user