diff --git a/mtapi_c/include/embb/mtapi/c/mtapi.h b/mtapi_c/include/embb/mtapi/c/mtapi.h index 38e9341..4ebadba 100644 --- a/mtapi_c/include/embb/mtapi/c/mtapi.h +++ b/mtapi_c/include/embb/mtapi/c/mtapi.h @@ -557,6 +557,17 @@ enum mtapi_node_attributes_enum { #define MTAPI_NODE_TYPE_SMP 1 #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 */ enum mtapi_task_attributes_enum { MTAPI_TASK_DETACHED, /**< task is detached, i.e., the runtime @@ -574,7 +585,9 @@ enum mtapi_task_attributes_enum { executed n times, if possible in parallel */ 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 */ #define MTAPI_TASK_DETACHED_SIZE sizeof(mtapi_boolean_t) @@ -671,6 +684,10 @@ struct mtapi_task_attributes_struct { mtapi_uint_t num_instances; /**< stores MTAPI_TASK_INSTANCES */ mtapi_uint_t priority; /**< stores MTAPI_TASK_PRIORITY */ 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 { mtapi_task_id_t id; /**< pool index of this handle */ }; -/** - * Task handle type. - * \memberof mtapi_task_hndl_struct - */ -typedef struct mtapi_task_hndl_struct mtapi_task_hndl_t; +// was forward declared +//typedef struct mtapi_task_hndl_struct mtapi_task_hndl_t; /* ---- BASIC CONSTANTS ---------------------------------------------------- */ diff --git a/mtapi_c/src/embb_mtapi_action_t.c b/mtapi_c/src/embb_mtapi_action_t.c index b21ba35..f79f03d 100644 --- a/mtapi_c/src/embb_mtapi_action_t.c +++ b/mtapi_c/src/embb_mtapi_action_t.c @@ -56,6 +56,7 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) { that->enabled = MTAPI_FALSE; that->node_local_data = NULL; that->node_local_data_size = 0; + that->plugin_data = MTAPI_NULL; embb_atomic_store_int(&that->num_tasks, 0); } diff --git a/mtapi_c/src/embb_mtapi_scheduler_t.c b/mtapi_c/src/embb_mtapi_scheduler_t.c index fe7499e..cbcf914 100644 --- a/mtapi_c/src/embb_mtapi_scheduler_t.c +++ b/mtapi_c/src/embb_mtapi_scheduler_t.c @@ -345,6 +345,11 @@ int embb_mtapi_scheduler_worker(void * arg) { /* do nothing, although this is an error */ 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) { /* spin and yield for a while before going to sleep */ embb_thread_yield(); diff --git a/mtapi_c/src/mtapi_task_attributes_t.c b/mtapi_c/src/mtapi_task_attributes_t.c index 718181f..ee3e166 100644 --- a/mtapi_c/src/mtapi_task_attributes_t.c +++ b/mtapi_c/src/mtapi_task_attributes_t.c @@ -25,6 +25,7 @@ */ #include +#include #include @@ -46,6 +47,7 @@ void mtapi_taskattr_init( attributes->num_instances = 1; attributes->is_detached = MTAPI_FALSE; attributes->priority = 0; + attributes->complete_func = MTAPI_NULL; mtapi_affinity_init(&attributes->affinity, MTAPI_TRUE, &local_status); } else { local_status = MTAPI_ERR_PARAMETER; @@ -90,6 +92,16 @@ void mtapi_taskattr_set( &attributes->affinity, attribute, attribute_size); 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: /* attribute unknown */ local_status = MTAPI_ERR_ATTR_NUM;