Commit ad97663c by Marcus Winter

mtapi_c: added task completion callback and user_data pointer

parent c7ba5e6a
...@@ -557,6 +557,17 @@ enum mtapi_node_attributes_enum { ...@@ -557,6 +557,17 @@ enum mtapi_node_attributes_enum {
#define MTAPI_NODE_TYPE_SMP 1 #define MTAPI_NODE_TYPE_SMP 1
#define MTAPI_NODE_TYPE_DSP 2 #define MTAPI_NODE_TYPE_DSP 2
/**
* Task handle type.
* \memberof mtapi_task_hndl_struct
*/
typedef struct mtapi_task_hndl_struct mtapi_task_hndl_t;
/** task completion callback */
typedef void(*mtapi_task_complete_function_t)(
MTAPI_IN mtapi_task_hndl_t task,
MTAPI_OUT mtapi_status_t* status);
/** task attributes */ /** task attributes */
enum mtapi_task_attributes_enum { enum mtapi_task_attributes_enum {
MTAPI_TASK_DETACHED, /**< task is detached, i.e., the runtime MTAPI_TASK_DETACHED, /**< task is detached, i.e., the runtime
...@@ -574,7 +585,9 @@ enum mtapi_task_attributes_enum { ...@@ -574,7 +585,9 @@ enum mtapi_task_attributes_enum {
executed n times, if possible in executed n times, if possible in
parallel */ parallel */
MTAPI_TASK_PRIORITY, MTAPI_TASK_PRIORITY,
MTAPI_TASK_AFFINITY MTAPI_TASK_AFFINITY,
MTAPI_TASK_USER_DATA,
MTAPI_TASK_COMPLETE_FUNCTION
}; };
/** size of the \a MTAPI_TASK_DETACHED attribute */ /** size of the \a MTAPI_TASK_DETACHED attribute */
#define MTAPI_TASK_DETACHED_SIZE sizeof(mtapi_boolean_t) #define MTAPI_TASK_DETACHED_SIZE sizeof(mtapi_boolean_t)
...@@ -671,6 +684,10 @@ struct mtapi_task_attributes_struct { ...@@ -671,6 +684,10 @@ struct mtapi_task_attributes_struct {
mtapi_uint_t num_instances; /**< stores MTAPI_TASK_INSTANCES */ mtapi_uint_t num_instances; /**< stores MTAPI_TASK_INSTANCES */
mtapi_uint_t priority; /**< stores MTAPI_TASK_PRIORITY */ mtapi_uint_t priority; /**< stores MTAPI_TASK_PRIORITY */
mtapi_affinity_t affinity; /**< stores MTAPI_TASK_AFFINITY */ mtapi_affinity_t affinity; /**< stores MTAPI_TASK_AFFINITY */
void * user_data; /**< stores MTAPI_TASK_USER_DATA */
mtapi_task_complete_function_t
complete_func; /**< stores
MTAPI_TASK_COMPLETE_FUNCTION */
}; };
/** /**
...@@ -869,11 +886,8 @@ struct mtapi_task_hndl_struct { ...@@ -869,11 +886,8 @@ struct mtapi_task_hndl_struct {
mtapi_task_id_t id; /**< pool index of this handle */ mtapi_task_id_t id; /**< pool index of this handle */
}; };
/** // was forward declared
* Task handle type. //typedef struct mtapi_task_hndl_struct mtapi_task_hndl_t;
* \memberof mtapi_task_hndl_struct
*/
typedef struct mtapi_task_hndl_struct mtapi_task_hndl_t;
/* ---- BASIC CONSTANTS ---------------------------------------------------- */ /* ---- BASIC CONSTANTS ---------------------------------------------------- */
......
...@@ -56,6 +56,7 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) { ...@@ -56,6 +56,7 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) {
that->enabled = MTAPI_FALSE; that->enabled = MTAPI_FALSE;
that->node_local_data = NULL; that->node_local_data = NULL;
that->node_local_data_size = 0; that->node_local_data_size = 0;
that->plugin_data = MTAPI_NULL;
embb_atomic_store_int(&that->num_tasks, 0); embb_atomic_store_int(&that->num_tasks, 0);
} }
......
...@@ -345,6 +345,11 @@ int embb_mtapi_scheduler_worker(void * arg) { ...@@ -345,6 +345,11 @@ int embb_mtapi_scheduler_worker(void * arg) {
/* do nothing, although this is an error */ /* do nothing, although this is an error */
break; break;
} }
/* issue task complete callback if set */
if (MTAPI_NULL != task->attributes.complete_func) {
task->attributes.complete_func(task->handle, MTAPI_NULL);
}
} else if (counter < 1024) { } else if (counter < 1024) {
/* spin and yield for a while before going to sleep */ /* spin and yield for a while before going to sleep */
embb_thread_yield(); embb_thread_yield();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
*/ */
#include <assert.h> #include <assert.h>
#include <string.h>
#include <embb/mtapi/c/mtapi.h> #include <embb/mtapi/c/mtapi.h>
...@@ -46,6 +47,7 @@ void mtapi_taskattr_init( ...@@ -46,6 +47,7 @@ void mtapi_taskattr_init(
attributes->num_instances = 1; attributes->num_instances = 1;
attributes->is_detached = MTAPI_FALSE; attributes->is_detached = MTAPI_FALSE;
attributes->priority = 0; attributes->priority = 0;
attributes->complete_func = MTAPI_NULL;
mtapi_affinity_init(&attributes->affinity, MTAPI_TRUE, &local_status); mtapi_affinity_init(&attributes->affinity, MTAPI_TRUE, &local_status);
} else { } else {
local_status = MTAPI_ERR_PARAMETER; local_status = MTAPI_ERR_PARAMETER;
...@@ -90,6 +92,16 @@ void mtapi_taskattr_set( ...@@ -90,6 +92,16 @@ void mtapi_taskattr_set(
&attributes->affinity, attribute, attribute_size); &attributes->affinity, attribute, attribute_size);
break; break;
case MTAPI_TASK_USER_DATA:
attributes->user_data = (void*)attribute;
local_status = MTAPI_SUCCESS;
break;
case MTAPI_TASK_COMPLETE_FUNCTION:
memcpy(&attributes->complete_func, &attribute, sizeof(void*));
local_status = MTAPI_SUCCESS;
break;
default: default:
/* attribute unknown */ /* attribute unknown */
local_status = MTAPI_ERR_ATTR_NUM; local_status = MTAPI_ERR_ATTR_NUM;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment