Commit f670df71 by Marcus Winter

mtapi_c: fixed codesonar warnings

parent ef7f44c1
......@@ -115,29 +115,33 @@ void mtapi_initialize(
node->attributes.max_tasks);
node->queue_pool = embb_mtapi_queue_pool_new(
node->attributes.max_queues);
if (MTAPI_NULL == node->job_list ||
MTAPI_NULL == node->action_pool ||
MTAPI_NULL == node->group_pool ||
MTAPI_NULL == node->task_pool ||
MTAPI_NULL == node->queue_pool) {
mtapi_finalize(NULL);
local_status = MTAPI_ERR_NODE_INITFAILED;
}
/* initialize scheduler for local node */
node->scheduler = embb_mtapi_scheduler_new();
if (MTAPI_NULL != node->scheduler) {
/* fill information structure */
node->info.hardware_concurrency = embb_core_count_available();
node->info.used_memory = embb_mtapi_alloc_get_bytes_allocated();
if (MTAPI_NULL != mtapi_info) {
*mtapi_info = node->info;
}
/* initialization succeeded, tell workers to start working */
embb_atomic_store_int(&node->is_scheduler_running, MTAPI_TRUE);
if (MTAPI_SUCCESS != local_status) {
if (local_status == MTAPI_SUCCESS) {
/* initialize scheduler for local node */
node->scheduler = embb_mtapi_scheduler_new();
if (MTAPI_NULL != node->scheduler) {
/* fill information structure */
node->info.hardware_concurrency = embb_core_count_available();
node->info.used_memory = embb_mtapi_alloc_get_bytes_allocated();
if (MTAPI_NULL != mtapi_info) {
*mtapi_info = node->info;
}
/* initialization succeeded, tell workers to start working */
embb_atomic_store_int(&node->is_scheduler_running, MTAPI_TRUE);
} else {
mtapi_finalize(MTAPI_NULL);
local_status = MTAPI_ERR_NODE_INITFAILED;
}
} else {
mtapi_finalize(MTAPI_NULL);
local_status = MTAPI_ERR_NODE_INITFAILED;
}
} else {
embb_mtapi_alloc_deallocate(node);
local_status = MTAPI_ERR_PARAMETER;
......@@ -163,19 +167,29 @@ void mtapi_finalize(MTAPI_OUT mtapi_status_t* status) {
}
/* finalize storage in reverse order */
embb_mtapi_queue_pool_delete(node->queue_pool);
node->queue_pool = MTAPI_NULL;
if (MTAPI_NULL != node->queue_pool) {
embb_mtapi_queue_pool_delete(node->queue_pool);
node->queue_pool = MTAPI_NULL;
}
embb_mtapi_task_pool_delete(node->task_pool);
node->task_pool = MTAPI_NULL;
if (MTAPI_NULL != node->task_pool) {
embb_mtapi_task_pool_delete(node->task_pool);
node->task_pool = MTAPI_NULL;
}
embb_mtapi_group_pool_delete(node->group_pool);
node->group_pool = MTAPI_NULL;
if (MTAPI_NULL != node->group_pool) {
embb_mtapi_group_pool_delete(node->group_pool);
node->group_pool = MTAPI_NULL;
}
embb_mtapi_action_pool_delete(node->action_pool);
node->action_pool = MTAPI_NULL;
if (MTAPI_NULL != node->action_pool) {
embb_mtapi_action_pool_delete(node->action_pool);
node->action_pool = MTAPI_NULL;
}
embb_mtapi_job_finalize_list(node);
if (MTAPI_NULL != node->job_list) {
embb_mtapi_job_finalize_list(node);
}
/* free system instance */
embb_mtapi_alloc_deallocate(node);
......
......@@ -456,6 +456,10 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
that->worker_contexts = (embb_mtapi_thread_context_t*)
embb_mtapi_alloc_allocate(
sizeof(embb_mtapi_thread_context_t)*that->worker_count);
if (NULL == that->worker_contexts) {
return MTAPI_FALSE;
}
mtapi_boolean_t isinit = MTAPI_TRUE;
for (ii = 0; ii < that->worker_count; ii++) {
unsigned int core_num = 0;
mtapi_uint_t ll = 0;
......@@ -467,9 +471,12 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
}
core_num++;
}
embb_mtapi_thread_context_initialize_with_node_worker_and_core(
isinit &= embb_mtapi_thread_context_initialize_with_node_worker_and_core(
&that->worker_contexts[ii], node, ii, core_num);
}
if (!isinit) {
return MTAPI_FALSE;
}
for (ii = 0; ii < that->worker_count; ii++) {
if (MTAPI_FALSE == embb_mtapi_thread_context_start(
&that->worker_contexts[ii], that)) {
......@@ -486,17 +493,19 @@ void embb_mtapi_scheduler_finalize(embb_mtapi_scheduler_t * that) {
assert(MTAPI_NULL != that);
/* finalize all workers */
for (ii = 0; ii < that->worker_count; ii++) {
embb_mtapi_thread_context_stop(&that->worker_contexts[ii]);
}
for (ii = 0; ii < that->worker_count; ii++) {
embb_mtapi_thread_context_finalize(&that->worker_contexts[ii]);
}
if (MTAPI_NULL != that->worker_contexts) {
/* finalize all workers */
for (ii = 0; ii < that->worker_count; ii++) {
embb_mtapi_thread_context_stop(&that->worker_contexts[ii]);
}
for (ii = 0; ii < that->worker_count; ii++) {
embb_mtapi_thread_context_finalize(&that->worker_contexts[ii]);
}
that->worker_count = 0;
embb_mtapi_alloc_deallocate(that->worker_contexts);
that->worker_contexts = MTAPI_NULL;
that->worker_count = 0;
embb_mtapi_alloc_deallocate(that->worker_contexts);
that->worker_contexts = MTAPI_NULL;
}
}
embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() {
......@@ -506,6 +515,7 @@ embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() {
if (MTAPI_NULL != that) {
if (MTAPI_FALSE == embb_mtapi_scheduler_initialize(that)) {
/* on error delete and return MTAPI_NULL */
embb_mtapi_scheduler_finalize(that);
embb_mtapi_scheduler_delete(that);
return MTAPI_NULL;
}
......
......@@ -38,12 +38,13 @@
/* ---- CLASS MEMBERS ------------------------------------------------------ */
void embb_mtapi_thread_context_initialize_with_node_worker_and_core(
mtapi_boolean_t embb_mtapi_thread_context_initialize_with_node_worker_and_core(
embb_mtapi_thread_context_t* that,
embb_mtapi_node_t* node,
mtapi_uint_t worker_index,
mtapi_uint_t core_num) {
mtapi_uint_t ii;
mtapi_boolean_t result = MTAPI_TRUE;
assert(MTAPI_NULL != that);
assert(MTAPI_NULL != node);
......@@ -52,25 +53,55 @@ void embb_mtapi_thread_context_initialize_with_node_worker_and_core(
that->worker_index = worker_index;
that->core_num = core_num;
that->priorities = node->attributes.max_priorities;
that->is_initialized = MTAPI_FALSE;
embb_atomic_store_int(&that->run, 0);
that->queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate(
sizeof(embb_mtapi_task_queue_t)*that->priorities);
that->private_queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate(
sizeof(embb_mtapi_task_queue_t)*that->priorities);
if (that->queue == NULL) {
that->private_queue = NULL;
return MTAPI_FALSE;
}
for (ii = 0; ii < that->priorities; ii++) {
that->queue[ii] = (embb_mtapi_task_queue_t*)
embb_mtapi_alloc_allocate(sizeof(embb_mtapi_task_queue_t));
embb_mtapi_task_queue_initialize_with_capacity(
that->queue[ii], node->attributes.queue_limit);
if (that->queue[ii] != NULL) {
embb_mtapi_task_queue_initialize_with_capacity(
that->queue[ii], node->attributes.queue_limit);
} else {
result = MTAPI_FALSE;
}
}
if (!result) {
return MTAPI_FALSE;
}
that->private_queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate(
sizeof(embb_mtapi_task_queue_t)*that->priorities);
if (that->private_queue == NULL) {
return MTAPI_FALSE;
}
for (ii = 0; ii < that->priorities; ii++) {
that->private_queue[ii] = (embb_mtapi_task_queue_t*)
embb_mtapi_alloc_allocate(sizeof(embb_mtapi_task_queue_t));
embb_mtapi_task_queue_initialize_with_capacity(
that->private_queue[ii], node->attributes.queue_limit);
if (that->private_queue[ii] != NULL) {
embb_mtapi_task_queue_initialize_with_capacity(
that->private_queue[ii], node->attributes.queue_limit);
} else {
result = MTAPI_FALSE;
}
}
if (!result) {
return MTAPI_FALSE;
}
embb_mutex_init(&that->work_available_mutex, EMBB_MUTEX_PLAIN);
embb_condition_init(&that->work_available);
embb_atomic_store_int(&that->is_sleeping, 0);
that->is_initialized = MTAPI_TRUE;
return MTAPI_TRUE;
}
mtapi_boolean_t embb_mtapi_thread_context_start(
......@@ -126,22 +157,37 @@ void embb_mtapi_thread_context_finalize(embb_mtapi_thread_context_t* that) {
embb_mtapi_log_trace("embb_mtapi_thread_context_finalize() called\n");
embb_condition_destroy(&that->work_available);
embb_mutex_destroy(&that->work_available_mutex);
if (that->is_initialized) {
embb_condition_destroy(&that->work_available);
embb_mutex_destroy(&that->work_available_mutex);
}
for (ii = 0; ii < that->priorities; ii++) {
embb_mtapi_task_queue_finalize(that->queue[ii]);
embb_mtapi_alloc_deallocate(that->queue[ii]);
that->queue[ii] = MTAPI_NULL;
embb_mtapi_task_queue_finalize(that->private_queue[ii]);
embb_mtapi_alloc_deallocate(that->private_queue[ii]);
that->private_queue[ii] = MTAPI_NULL;
if (that->queue != NULL) {
for (ii = 0; ii < that->priorities; ii++) {
if (that->queue[ii] != NULL) {
embb_mtapi_task_queue_finalize(that->queue[ii]);
embb_mtapi_alloc_deallocate(that->queue[ii]);
that->queue[ii] = MTAPI_NULL;
}
}
embb_mtapi_alloc_deallocate(that->queue);
that->queue = MTAPI_NULL;
}
embb_mtapi_alloc_deallocate(that->queue);
that->queue = MTAPI_NULL;
embb_mtapi_alloc_deallocate(that->private_queue);
that->private_queue = MTAPI_NULL;
if (that->private_queue != NULL) {
for (ii = 0; ii < that->priorities; ii++) {
if (that->private_queue[ii] != NULL) {
embb_mtapi_task_queue_finalize(that->private_queue[ii]);
embb_mtapi_alloc_deallocate(that->private_queue[ii]);
that->private_queue[ii] = MTAPI_NULL;
}
}
embb_mtapi_alloc_deallocate(that->private_queue);
that->private_queue = MTAPI_NULL;
}
that->priorities = 0;
that->is_initialized = MTAPI_FALSE;
that->node = MTAPI_NULL;
}
......
......@@ -67,6 +67,7 @@ struct embb_mtapi_thread_context_struct {
mtapi_uint_t core_num;
embb_atomic_int run;
mtapi_status_t status;
mtapi_boolean_t is_initialized;
};
#include <embb_mtapi_thread_context_t_fwd.h>
......@@ -74,8 +75,9 @@ struct embb_mtapi_thread_context_struct {
/**
* Constructor using attributes from node and a given core number.
* \memberof embb_mtapi_thread_context_struct
* \returns MTAPI_TRUE if successful, MTAPI_FALSE on error
*/
void embb_mtapi_thread_context_initialize_with_node_worker_and_core(
mtapi_boolean_t embb_mtapi_thread_context_initialize_with_node_worker_and_core(
embb_mtapi_thread_context_t* that,
embb_mtapi_node_t* node,
mtapi_uint_t worker_index,
......
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