From f45a930eaaba37cdcba199ee8fc12e7120f828c2 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Tue, 24 Feb 2015 15:44:59 +0100 Subject: [PATCH] mtapi_c: fixed minor bugs --- mtapi_c/src/embb_mtapi_action_t.c | 1 + mtapi_c/src/embb_mtapi_id_pool_t.c | 6 +++--- mtapi_c/src/embb_mtapi_job_t.c | 10 +++++----- mtapi_c/src/embb_mtapi_pool_template-inl.h | 6 +++--- mtapi_c/src/embb_mtapi_queue_t.c | 1 + 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mtapi_c/src/embb_mtapi_action_t.c b/mtapi_c/src/embb_mtapi_action_t.c index 6c57c7e..eeeaf83 100644 --- a/mtapi_c/src/embb_mtapi_action_t.c +++ b/mtapi_c/src/embb_mtapi_action_t.c @@ -412,6 +412,7 @@ void mtapi_action_enable( embb_mtapi_action_pool_get_storage_for_handle( node->action_pool, action); local_action->enabled = MTAPI_TRUE; + local_status = MTAPI_SUCCESS; } else { local_status = MTAPI_ERR_ACTION_INVALID; } diff --git a/mtapi_c/src/embb_mtapi_id_pool_t.c b/mtapi_c/src/embb_mtapi_id_pool_t.c index 08869b6..570fa98 100644 --- a/mtapi_c/src/embb_mtapi_id_pool_t.c +++ b/mtapi_c/src/embb_mtapi_id_pool_t.c @@ -37,12 +37,12 @@ void embb_mtapi_id_pool_initialize( that->capacity = capacity; that->id_buffer = (mtapi_uint_t*) - embb_mtapi_alloc_allocate(sizeof(mtapi_uint_t)*(capacity)); + embb_mtapi_alloc_allocate(sizeof(mtapi_uint_t)*(capacity + 1)); that->id_buffer[0] = EMBB_MTAPI_IDPOOL_INVALID_ID; - for (ii = 1; ii < capacity; ii++) { + for (ii = 1; ii <= capacity; ii++) { that->id_buffer[ii] = ii; } - that->ids_available = capacity - 1; + that->ids_available = capacity; that->put_id_position = 0; that->get_id_position = 1; embb_mtapi_spinlock_initialize(&that->lock); diff --git a/mtapi_c/src/embb_mtapi_job_t.c b/mtapi_c/src/embb_mtapi_job_t.c index 6064208..227666e 100644 --- a/mtapi_c/src/embb_mtapi_job_t.c +++ b/mtapi_c/src/embb_mtapi_job_t.c @@ -40,9 +40,9 @@ mtapi_boolean_t embb_mtapi_job_initialize_list(embb_mtapi_node_t * node) { node->job_list = (embb_mtapi_job_t*)embb_mtapi_alloc_allocate( - sizeof(embb_mtapi_job_t)*node->attributes.max_jobs); + sizeof(embb_mtapi_job_t)*(node->attributes.max_jobs + 1)); mtapi_uint_t ii; - for (ii = 0; ii < node->attributes.max_jobs; ii++) { + for (ii = 0; ii <= node->attributes.max_jobs; ii++) { embb_mtapi_job_initialize( &node->job_list[ii], node->attributes.max_actions_per_job); node->job_list[ii].handle.id = ii; @@ -53,7 +53,7 @@ mtapi_boolean_t embb_mtapi_job_initialize_list(embb_mtapi_node_t * node) { void embb_mtapi_job_finalize_list(embb_mtapi_node_t * node) { mtapi_uint_t ii; - for (ii = 0; ii < node->attributes.max_jobs; ii++) { + for (ii = 0; ii <= node->attributes.max_jobs; ii++) { embb_mtapi_job_finalize(&node->job_list[ii]); node->job_list[ii].handle.id = 0; } @@ -69,7 +69,7 @@ mtapi_boolean_t embb_mtapi_job_is_handle_valid( mtapi_job_hndl_t handle) { assert(MTAPI_NULL != node); return ((0 < handle.id) && - (handle.id < node->attributes.max_jobs) && + (handle.id <= node->attributes.max_jobs) && (node->job_list[handle.id].handle.tag == handle.tag)) ? MTAPI_TRUE : MTAPI_FALSE; } @@ -87,7 +87,7 @@ mtapi_boolean_t embb_mtapi_job_is_id_valid( embb_mtapi_node_t * node, mtapi_job_id_t id) { assert(MTAPI_NULL != node); - return ((0 < id) && (id < node->attributes.max_jobs)) ? + return ((0 < id) && (id <= node->attributes.max_jobs)) ? MTAPI_TRUE : MTAPI_FALSE; } diff --git a/mtapi_c/src/embb_mtapi_pool_template-inl.h b/mtapi_c/src/embb_mtapi_pool_template-inl.h index 76860e9..5366972 100644 --- a/mtapi_c/src/embb_mtapi_pool_template-inl.h +++ b/mtapi_c/src/embb_mtapi_pool_template-inl.h @@ -60,8 +60,8 @@ mtapi_boolean_t embb_mtapi_##TYPE##_pool_initialize( \ assert(MTAPI_NULL != that); \ embb_mtapi_id_pool_initialize(&that->id_pool, capacity); \ that->storage = (embb_mtapi_##TYPE##_t*)embb_mtapi_alloc_allocate( \ - sizeof(embb_mtapi_##TYPE##_t)*capacity); \ - for (ii = 0; ii < capacity; ii++) { \ + sizeof(embb_mtapi_##TYPE##_t)*(capacity + 1)); \ + for (ii = 0; ii <= capacity; ii++) { \ that->storage[ii].handle.id = EMBB_MTAPI_IDPOOL_INVALID_ID; \ that->storage[ii].handle.tag = 0; \ } \ @@ -102,7 +102,7 @@ mtapi_boolean_t embb_mtapi_##TYPE##_pool_is_handle_valid( \ mtapi_##TYPE##_hndl_t handle) { \ assert(MTAPI_NULL != that); \ return ((0 < handle.id) && \ - (handle.id < that->id_pool.capacity) && \ + (handle.id <= that->id_pool.capacity) && \ (that->storage[handle.id].handle.tag == handle.tag)) ? \ MTAPI_TRUE : MTAPI_FALSE; \ } \ diff --git a/mtapi_c/src/embb_mtapi_queue_t.c b/mtapi_c/src/embb_mtapi_queue_t.c index 5346046..8288dab 100644 --- a/mtapi_c/src/embb_mtapi_queue_t.c +++ b/mtapi_c/src/embb_mtapi_queue_t.c @@ -200,6 +200,7 @@ mtapi_queue_hndl_t mtapi_queue_create( queue->queue_id = queue_id; queue_hndl = queue->handle; } else { + embb_mtapi_queue_pool_deallocate(node->queue_pool, queue); local_status = MTAPI_ERR_JOB_INVALID; } } else { -- libgit2 0.26.0