diff core/RTAudio.cpp @ 258:88cf310417cd aux_task_args

Add a parameter 'autoSchedule' to createAuxiliaryTask() which when true causes the task to be automatically scheduled after every render function call, without the user needing to call scheduleAuxiliaryTask()
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Sat, 07 May 2016 13:23:15 +0100
parents 3e93d9793da3
children c55c6f6c233c
line wrap: on
line diff
--- a/core/RTAudio.cpp	Sat May 07 12:51:10 2016 +0100
+++ b/core/RTAudio.cpp	Sat May 07 13:23:15 2016 +0100
@@ -48,6 +48,7 @@
 	bool started;
 	bool hasArgs;
 	void* args;
+	bool autoSchedule;
 } InternalAuxiliaryTask;
 
 const char gRTAudioThreadName[] = "beaglert-audio";
@@ -294,7 +295,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* args), int priority, const char *name, void* args)
+AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void* args), int priority, const char *name, void* args, bool autoSchedule)
 {
 	InternalAuxiliaryTask *newTask = (InternalAuxiliaryTask*)malloc(sizeof(InternalAuxiliaryTask));
 
@@ -312,27 +313,33 @@
 	newTask->started = false;
 	newTask->args = args;
 	newTask->hasArgs = true;
-
+    newTask->autoSchedule = autoSchedule;
+    
 	getAuxTasks().push_back(newTask);
 
 	return (AuxiliaryTask)newTask;
 }
-AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void), int priority, const char *name)
+AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void), int priority, const char *name, bool autoSchedule)
 {
         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;
+        newTask->autoSchedule = autoSchedule;
+        
         getAuxTasks().push_back(newTask);
+        
         return (AuxiliaryTask)newTask;
 }
 
@@ -347,6 +354,14 @@
 	}
 	rt_task_resume(&taskToSchedule->task);
 }
+void BeagleRT_autoScheduleAuxiliaryTasks(){
+    vector<InternalAuxiliaryTask*>::iterator it;
+	for(it = getAuxTasks().begin(); it != getAuxTasks().end(); it++) {
+	    if ((InternalAuxiliaryTask *)(*it)->autoSchedule){
+    		BeagleRT_scheduleAuxiliaryTask(*it);
+	    }
+	}
+}
 
 // Calculation loop that can be used for other tasks running at a lower
 // priority than the audio thread. Simple wrapper for Xenomai calls.
@@ -359,7 +374,7 @@
 	void (*auxiliary_argfunction)(void* args) = task->argfunction;
     void (*auxiliary_function)(void) = task->function;
     
-    // get the name
+    // get the task's name
 	const char *name = task->name;
 
 	// Wait for a notification