Commit f9fd8a10 by Marcus Winter Committed by unknown

mtapi_c: extended action plugin api, some cleanup

parent d6306e93
......@@ -36,20 +36,27 @@ extern "C" {
#endif
typedef void(*mtapi_ext_plugin_action_start_function_t)(
typedef void(*mtapi_ext_plugin_task_start_function_t)(
MTAPI_IN mtapi_task_hndl_t task,
MTAPI_OUT mtapi_status_t* status
);
typedef void(*mtapi_ext_plugin_action_cancel_function_t)(
typedef void(*mtapi_ext_plugin_task_cancel_function_t)(
MTAPI_IN mtapi_task_hndl_t task,
MTAPI_OUT mtapi_status_t* status
);
typedef void(*mtapi_ext_plugin_action_finalize_function_t)(
MTAPI_IN mtapi_action_hndl_t action,
MTAPI_OUT mtapi_status_t* status
);
mtapi_action_hndl_t mtapi_ext_plugin_action_create(
MTAPI_IN mtapi_job_id_t job_id,
MTAPI_IN mtapi_ext_plugin_action_start_function_t start_function,
MTAPI_IN mtapi_ext_plugin_action_cancel_function_t cancel_function,
MTAPI_IN mtapi_ext_plugin_task_start_function_t task_start_function,
MTAPI_IN mtapi_ext_plugin_task_cancel_function_t task_cancel_function,
MTAPI_IN mtapi_ext_plugin_action_finalize_function_t action_finalize_function,
MTAPI_IN void* plugin_data,
MTAPI_IN void* node_local_data,
MTAPI_IN mtapi_size_t node_local_data_size,
MTAPI_IN mtapi_action_attributes_t* attributes,
......
......@@ -33,8 +33,10 @@
mtapi_action_hndl_t mtapi_ext_plugin_action_create(
MTAPI_IN mtapi_job_id_t job_id,
MTAPI_IN mtapi_ext_plugin_action_start_function_t start_function,
MTAPI_IN mtapi_ext_plugin_action_cancel_function_t cancel_function,
MTAPI_IN mtapi_ext_plugin_task_start_function_t task_start_function,
MTAPI_IN mtapi_ext_plugin_task_cancel_function_t task_cancel_function,
MTAPI_IN mtapi_ext_plugin_action_finalize_function_t action_finalize_function,
MTAPI_IN void* plugin_data,
MTAPI_IN void* node_local_data,
MTAPI_IN mtapi_size_t node_local_data_size,
MTAPI_IN mtapi_action_attributes_t* attributes,
......@@ -61,8 +63,10 @@ mtapi_action_hndl_t mtapi_ext_plugin_action_create(
new_action->is_plugin_action = MTAPI_TRUE;
embb_atomic_store_int(&new_action->num_tasks, 0);
new_action->plugin_start_function = start_function;
new_action->plugin_cancel_function = cancel_function;
new_action->plugin_task_start_function = task_start_function;
new_action->plugin_task_cancel_function = task_cancel_function;
new_action->plugin_action_finalize_function = action_finalize_function;
new_action->plugin_data = (void*)plugin_data;
/* set defaults if no attributes were given */
if (MTAPI_NULL != attributes) {
......
......@@ -60,6 +60,10 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) {
}
void embb_mtapi_action_finalize(embb_mtapi_action_t* that) {
if (that->is_plugin_action) {
// TODO: check status
that->plugin_action_finalize_function(that->handle, NULL);
}
embb_mtapi_action_initialize(that);
}
......@@ -324,7 +328,8 @@ void mtapi_action_delete(
node, local_action->job_id);
embb_mtapi_job_remove_action(local_job, local_action);
}
embb_mtapi_action_finalize(local_action);
/* this is done by pool deallocate:
embb_mtapi_action_finalize(local_action); */
embb_mtapi_action_pool_deallocate(node->action_pool, local_action);
} else {
local_status = MTAPI_ERR_ACTION_INVALID;
......
......@@ -58,8 +58,10 @@ struct embb_mtapi_action_struct {
mtapi_boolean_t enabled;
mtapi_boolean_t is_plugin_action;
mtapi_ext_plugin_action_start_function_t plugin_start_function;
mtapi_ext_plugin_action_cancel_function_t plugin_cancel_function;
void* plugin_data;
mtapi_ext_plugin_task_start_function_t plugin_task_start_function;
mtapi_ext_plugin_task_cancel_function_t plugin_task_cancel_function;
mtapi_ext_plugin_action_finalize_function_t plugin_action_finalize_function;
embb_atomic_int num_tasks;
};
......
......@@ -239,7 +239,7 @@ static mtapi_task_hndl_t embb_mtapi_task_start(
if (local_action->is_plugin_action) {
/* schedule plugin task */
mtapi_status_t plugin_status = MTAPI_ERR_UNKNOWN;
local_action->plugin_start_function(task_hndl, &plugin_status);
local_action->plugin_task_start_function(task_hndl, &plugin_status);
was_scheduled = (MTAPI_SUCCESS == plugin_status) ? MTAPI_TRUE : MTAPI_FALSE;
} else {
/* schedule local task */
......@@ -469,7 +469,7 @@ void mtapi_task_cancel(
embb_mtapi_action_t* local_action =
embb_mtapi_action_pool_get_storage_for_handle(node->action_pool, local_task->action);
if (local_action->is_plugin_action) {
local_action->plugin_cancel_function(task, &local_status);
local_action->plugin_task_cancel_function(task, &local_status);
}
} else {
local_status = MTAPI_SUCCESS;
......
......@@ -34,6 +34,7 @@
#include <embb/base/c/thread.h>
#include <embb/base/c/atomic.h>
#include <embb/base/c/internal/unused.h>
#define PLUGIN_JOB_ID 2
......@@ -43,6 +44,7 @@ mtapi_task_hndl_t plugin_task;
embb_atomic_int plugin_task_available;
int plugin_thread_function(void * args) {
EMBB_UNUSED(args);
while (embb_atomic_load_int(&plugin_running)) {
/* wait for incoming task */
while (embb_atomic_load_int(&plugin_running) && !embb_atomic_load_int(&plugin_task_available))
......@@ -70,6 +72,9 @@ void plugin_initialize(
MTAPI_IN mtapi_node_t node_id,
MTAPI_OUT mtapi_status_t* status
) {
EMBB_UNUSED(domain_id);
EMBB_UNUSED(node_id);
mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
int err;
......@@ -102,7 +107,7 @@ void plugin_finalize(
mtapi_status_set(status, local_status);
}
void plugin_action_start(
void plugin_task_start(
MTAPI_IN mtapi_task_hndl_t task,
MTAPI_OUT mtapi_status_t* status) {
mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
......@@ -125,15 +130,24 @@ void plugin_action_start(
mtapi_status_set(status, local_status);
}
void plugin_action_cancel(
void plugin_task_cancel(
MTAPI_IN mtapi_task_hndl_t task,
MTAPI_OUT mtapi_status_t* status
) {
EMBB_UNUSED(task);
mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
mtapi_status_set(status, local_status);
}
void plugin_action_finalize(
MTAPI_IN mtapi_action_hndl_t action,
MTAPI_OUT mtapi_status_t* status
) {
EMBB_UNUSED(action);
mtapi_status_set(status, MTAPI_SUCCESS);
}
PluginTest::PluginTest() {
CreateUnit("mtapi plugin test").
Add(&PluginTest::TestBasic, this);
......@@ -180,8 +194,10 @@ void PluginTest::TestBasic() {
status = MTAPI_ERR_UNKNOWN;
action = mtapi_ext_plugin_action_create(
PLUGIN_JOB_ID,
plugin_action_start,
plugin_action_cancel,
plugin_task_start,
plugin_task_cancel,
plugin_action_finalize,
MTAPI_NULL,
MTAPI_NULL,
0,
MTAPI_DEFAULT_ACTION_ATTRIBUTES,
......
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