From c837d9b028ad8cecc7e12320c9df1f9d224ca971 Mon Sep 17 00:00:00 2001 From: wellenvogel Date: Thu, 2 Dec 2021 17:43:47 +0100 Subject: [PATCH] allow to set the satck size for user tasks --- lib/api/GwApi.h | 3 +++ lib/exampletask/GwExampleTask.h | 6 +++++- lib/usercode/GwUserCode.cpp | 13 +++++++------ lib/usercode/GwUserCode.h | 7 +++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/api/GwApi.h b/lib/api/GwApi.h index 340e738..26c95e2 100644 --- a/lib/api/GwApi.h +++ b/lib/api/GwApi.h @@ -25,6 +25,9 @@ class GwApi{ #ifndef DECLARE_USERTASK #define DECLARE_USERTASK(task) #endif +#ifndef DECLARE_USERTASK_PARAM +#define DECLARE_USERTASK_PARAM(task,...) +#endif #ifndef DECLARE_INITFUNCTION #define DECLARE_INITFUNCTION(task) #endif diff --git a/lib/exampletask/GwExampleTask.h b/lib/exampletask/GwExampleTask.h index 3ea4bb1..ed84eb6 100644 --- a/lib/exampletask/GwExampleTask.h +++ b/lib/exampletask/GwExampleTask.h @@ -27,7 +27,11 @@ void exampleTask(GwApi *param); void exampleInit(GwApi *param); //make the task known to the core //the task function should not return (unless you delete the task - see example code) -DECLARE_USERTASK(exampleTask); +DECLARE_USERTASK(exampleTask) +//if your task needs more stack then the default 2000 bytes, replace the DECLARE_USERTASK +//with: DECLARE_USERTASK_PARAM(exampleTask,2500); +//this will give you 2500 bytes of stack + //let the core call an init function before the //N2K Stuff and the communication is set up //normally you should not need this at all diff --git a/lib/usercode/GwUserCode.cpp b/lib/usercode/GwUserCode.cpp index 3a96ed5..7f6da3e 100644 --- a/lib/usercode/GwUserCode.cpp +++ b/lib/usercode/GwUserCode.cpp @@ -15,11 +15,11 @@ GwUserCode::Capabilities userCapabilities; class GwUserTaskDef{ public: - GwUserTaskDef(TaskFunction_t task,String name){ - userTasks.push_back(GwUserTask(name,task)); + GwUserTaskDef(TaskFunction_t task,String name, int stackSize=2000){ + userTasks.push_back(GwUserTask(name,task,stackSize)); } - GwUserTaskDef(GwUserTaskFunction task,String name){ - userTasks.push_back(GwUserTask(name,task)); + GwUserTaskDef(GwUserTaskFunction task,String name,int stackSize=2000){ + userTasks.push_back(GwUserTask(name,task,stackSize)); } }; @@ -39,6 +39,7 @@ class GwUserCapability{ } }; #define DECLARE_USERTASK(task) GwUserTaskDef __##task##__(task,#task); +#define DECLARE_USERTASK_PARAM(task,...) GwUserTaskDef __##task##__(task,#task,__VA_ARGS__); #define DECLARE_INITFUNCTION(task) GwInitTask __Init##task##__(task,#task); #define DECLARE_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,#value); #include "GwApi.h" @@ -115,12 +116,12 @@ void userTaskStart(void *p){ } void GwUserCode::startAddOnTask(GwApi *api,GwUserTask *task,int sourceId,String name){ task->api=new TaskApi(api,sourceId,mainLock); - xTaskCreate(userTaskStart,name.c_str(),2000,task,3,NULL); + xTaskCreate(userTaskStart,name.c_str(),task->stackSize,task,3,NULL); } void GwUserCode::startUserTasks(int baseId){ LOG_DEBUG(GwLog::DEBUG,"starting %d user tasks",userTasks.size()); for (auto it=userTasks.begin();it != userTasks.end();it++){ - LOG_DEBUG(GwLog::LOG,"starting user task %s with id %d",it->name.c_str(),baseId); + LOG_DEBUG(GwLog::LOG,"starting user task %s with id %d, stackSize %d",it->name.c_str(), baseId,it->stackSize); startAddOnTask(api,&(*it),baseId,it->name); baseId++; } diff --git a/lib/usercode/GwUserCode.h b/lib/usercode/GwUserCode.h index 5d28e3e..47bc07e 100644 --- a/lib/usercode/GwUserCode.h +++ b/lib/usercode/GwUserCode.h @@ -12,14 +12,17 @@ class GwUserTask{ GwUserTaskFunction usertask=NULL; bool isUserTask=false; GwApi *api=NULL; - GwUserTask(String name,TaskFunction_t task){ + int stackSize=2000; + GwUserTask(String name,TaskFunction_t task,int stackSize=2000){ this->name=name; this->task=task; + this->stackSize=stackSize; } - GwUserTask(String name, GwUserTaskFunction task){ + GwUserTask(String name, GwUserTaskFunction task,int stackSize=2000){ this->name=name; this->usertask=task; this->isUserTask=true; + this->stackSize=stackSize; } }; class GwUserCode{