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 {
#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 ---------------------------------------------------- */
......
......@@ -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);
}
......
......@@ -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();
......
......@@ -25,6 +25,7 @@
*/
#include <assert.h>
#include <string.h>
#include <embb/mtapi/c/mtapi.h>
......@@ -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;
......
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