Mercurial > hg > beaglert
changeset 256:3e93d9793da3 aux_task_args
Overload BeagleRT_createAuxiliaryTask so tasks can be created with or without arguments
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Fri, 06 May 2016 21:36:27 +0100 |
parents | 173978a5ab6a |
children | 1606b50a58c6 |
files | core/RTAudio.cpp include/BeagleRT.h |
diffstat | 2 files changed, 36 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/core/RTAudio.cpp Tue May 03 11:04:56 2016 +0100 +++ b/core/RTAudio.cpp Fri May 06 21:36:27 2016 +0100 @@ -41,10 +41,12 @@ // can schedule typedef struct { RT_TASK task; - void (*function)(void*); + void (*argfunction)(void*); + void (*function)(void); char *name; int priority; bool started; + bool hasArgs; void* args; } InternalAuxiliaryTask; @@ -292,7 +294,7 @@ // (equal or lower) priority. Audio priority is defined in BEAGLERT_AUDIO_PRIORITY; // priority should be generally be less than this. // Returns an (opaque) pointer to the created task on success; 0 on failure -AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void*), int priority, const char *name, void* args) +AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void* args), int priority, const char *name, void* args) { InternalAuxiliaryTask *newTask = (InternalAuxiliaryTask*)malloc(sizeof(InternalAuxiliaryTask)); @@ -304,16 +306,35 @@ } // Populate the rest of the data structure and store it in the vector - newTask->function = functionToCall; + newTask->argfunction = functionToCall; newTask->name = strdup(name); newTask->priority = priority; newTask->started = false; newTask->args = args; + newTask->hasArgs = true; getAuxTasks().push_back(newTask); return (AuxiliaryTask)newTask; } +AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void), int priority, const char *name) +{ + InternalAuxiliaryTask *newTask = (InternalAuxiliaryTask*)malloc(sizeof(InternalAuxiliaryTask)); + // Attempt to create the task + if(rt_task_create(&(newTask->task), name, 0, priority, T_JOINABLE | T_FPU)) { + cout << "Error: unable to create auxiliary task " << name << endl; + free(newTask); + return 0; + } + // Populate the rest of the data structure and store it in the vector + newTask->function = functionToCall; + newTask->name = strdup(name); + newTask->priority = priority; + newTask->started = false; + newTask->hasArgs = false; + getAuxTasks().push_back(newTask); + return (AuxiliaryTask)newTask; +} // Schedule a previously created (and started) auxiliary task. It will run when the priority rules next // allow it to be scheduled. @@ -332,16 +353,24 @@ // Treat the argument as containing the task structure void auxiliaryTaskLoop(void *taskStruct) { + InternalAuxiliaryTask *task = ((InternalAuxiliaryTask *)taskStruct); + // Get function to call from the argument - void (*auxiliary_function)(void*) = ((InternalAuxiliaryTask *)taskStruct)->function; - const char *name = ((InternalAuxiliaryTask *)taskStruct)->name; + void (*auxiliary_argfunction)(void* args) = task->argfunction; + void (*auxiliary_function)(void) = task->function; + + // get the name + const char *name = task->name; // Wait for a notification rt_task_suspend(NULL); while(!gShouldStop) { // Then run the calculations - auxiliary_function(((InternalAuxiliaryTask *)taskStruct)->args); + if (task->hasArgs) + auxiliary_argfunction(task->args); + else + auxiliary_function(); // Wait for a notification rt_task_suspend(NULL);
--- a/include/BeagleRT.h Tue May 03 11:04:56 2016 +0100 +++ b/include/BeagleRT.h Fri May 06 21:36:27 2016 +0100 @@ -580,6 +580,7 @@ * \param name Name for this task, which should be unique system-wide (no other running program should use this name). */ AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void*), int priority, const char *name, void* args); +AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void), int priority, const char *name) /** * \brief Start an auxiliary task so that it can be run.