diff core/RTAudio.cpp @ 254:173978a5ab6a aux_task_args

Allow arguments to be passed to aux task function
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Tue, 03 May 2016 11:04:56 +0100
parents 18d03901f866
children 3e93d9793da3
line wrap: on
line diff
--- a/core/RTAudio.cpp	Thu Apr 28 19:40:41 2016 +0100
+++ b/core/RTAudio.cpp	Tue May 03 11:04:56 2016 +0100
@@ -41,10 +41,11 @@
 // can schedule
 typedef struct {
 	RT_TASK task;
-	void (*function)(void);
+	void (*function)(void*);
 	char *name;
 	int priority;
 	bool started;
+	void* args;
 } InternalAuxiliaryTask;
 
 const char gRTAudioThreadName[] = "beaglert-audio";
@@ -291,7 +292,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)
+AuxiliaryTask BeagleRT_createAuxiliaryTask(void (*functionToCall)(void*), int priority, const char *name, void* args)
 {
 	InternalAuxiliaryTask *newTask = (InternalAuxiliaryTask*)malloc(sizeof(InternalAuxiliaryTask));
 
@@ -307,6 +308,7 @@
 	newTask->name = strdup(name);
 	newTask->priority = priority;
 	newTask->started = false;
+	newTask->args = args;
 
 	getAuxTasks().push_back(newTask);
 
@@ -331,7 +333,7 @@
 void auxiliaryTaskLoop(void *taskStruct)
 {
 	// Get function to call from the argument
-	void (*auxiliary_function)(void) = ((InternalAuxiliaryTask *)taskStruct)->function;
+	void (*auxiliary_function)(void*) = ((InternalAuxiliaryTask *)taskStruct)->function;
 	const char *name = ((InternalAuxiliaryTask *)taskStruct)->name;
 
 	// Wait for a notification
@@ -339,7 +341,7 @@
 
 	while(!gShouldStop) {
 		// Then run the calculations
-		auxiliary_function();
+		auxiliary_function(((InternalAuxiliaryTask *)taskStruct)->args);
 
 		// Wait for a notification
 		rt_task_suspend(NULL);