diff --git a/src/qvi-bbuff.cc b/src/qvi-bbuff.cc index 2ad3d09a..b3dca9c2 100644 --- a/src/qvi-bbuff.cc +++ b/src/qvi-bbuff.cc @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-basic-offset:4; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2020-2022 Triad National Security, LLC + * Copyright (c) 2020-2024 Triad National Security, LLC * All rights reserved. * * Copyright (c) 2020-2021 Lawrence Livermore National Security, LLC @@ -16,8 +16,10 @@ #include "qvi-common.h" #include "qvi-bbuff.h" +#include "qvi-utils.h" struct qvi_bbuff_s { + int qvim_rc = QV_ERR_INTERNAL; /** Current capacity of buffer. */ size_t capacity = 0; /** Amount of data already stored. */ @@ -29,45 +31,36 @@ struct qvi_bbuff_s { /** Minimum growth in bytes for resizes, etc. */ min_growth = 256 } constants; + /** Constructor */ + qvi_bbuff_s(void) + { + capacity = min_growth; + data = calloc(capacity, sizeof(byte_t)); + if (!data) { + qvim_rc = QV_ERR_OOR; + return; + } + qvim_rc = QV_SUCCESS; + } + /** Destructor */ + ~qvi_bbuff_s(void) + { + if (data) free(data); + } }; int qvi_bbuff_new( qvi_bbuff_t **buff ) { - int rc = QV_SUCCESS; - - qvi_bbuff_t *ibuff = qvi_new qvi_bbuff_t(); - if (!ibuff) { - rc = QV_ERR_OOR; - goto out; - } - - ibuff->capacity = ibuff->min_growth; - ibuff->data = calloc(ibuff->capacity, sizeof(byte_t)); - if (!ibuff->data) { - rc = QV_ERR_OOR; - goto out; - } -out: - if (rc != QV_SUCCESS) { - qvi_bbuff_free(&ibuff); - } - *buff = ibuff; - return rc; + return qvi_new_rc(buff); } void qvi_bbuff_free( qvi_bbuff_t **buff ) { - if (!buff) return; - qvi_bbuff_t *ibuff = *buff; - if (!ibuff) goto out; - if (ibuff->data) free(ibuff->data); - delete ibuff; -out: - *buff = nullptr; + qvi_delete(buff); } void * diff --git a/src/qvi-bind.cc b/src/qvi-bind.cc index c47c6544..96e19c30 100644 --- a/src/qvi-bind.cc +++ b/src/qvi-bind.cc @@ -16,61 +16,43 @@ #include "qvi-common.h" // IWYU pragma: keep #include "qvi-bind.h" +#include "qvi-utils.h" using qvi_bind_bitmap_stack_t = std::stack; // Type definition struct qvi_bind_stack_s { + int qvim_rc = QV_SUCCESS; /** Initialized task instance. */ qvi_task_t *task = nullptr; /** Client RMI instance. */ qvi_rmi_client_t *rmi = nullptr; /** The bind stack. */ - qvi_bind_bitmap_stack_t *stack = nullptr; + qvi_bind_bitmap_stack_t stack; + /** Constructor */ + qvi_bind_stack_s(void) = default; + /** Destructor */ + ~qvi_bind_stack_s(void) + { + while (!stack.empty()) { + hwloc_bitmap_free(stack.top()); + stack.pop(); + } + } }; int qvi_bind_stack_new( qvi_bind_stack_t **bstack ) { - int rc = QV_SUCCESS; - - qvi_bind_stack_t *ibstack = qvi_new qvi_bind_stack_t(); - if (!ibstack) { - rc = QV_ERR_OOR; - goto out; - } - - ibstack->stack = qvi_new qvi_bind_bitmap_stack_t(); - if (!ibstack->stack) { - rc = QV_ERR_OOR; - } -out: - if (rc != QV_SUCCESS) { - qvi_bind_stack_free(&ibstack); - } - *bstack = ibstack; - return rc; + return qvi_new_rc(bstack); } void qvi_bind_stack_free( qvi_bind_stack_t **bstack ) { - if (!bstack) return; - qvi_bind_stack_t *ibstack = *bstack; - if (!ibstack) goto out; - if (ibstack->stack) { - while (!ibstack->stack->empty()) { - hwloc_cpuset_t bitm = ibstack->stack->top(); - hwloc_bitmap_free(bitm); - ibstack->stack->pop(); - } - } - delete ibstack->stack; - delete ibstack; -out: - *bstack = nullptr; + qvi_delete(bstack); } int @@ -91,7 +73,7 @@ qvi_bind_stack_init( ); if (rc != QV_SUCCESS) goto out; - bstack->stack->push(current_bind); + bstack->stack.push(current_bind); out: if (rc != QV_SUCCESS) { hwloc_bitmap_free(current_bind); @@ -119,7 +101,7 @@ qvi_bind_push( ); if (rc != QV_SUCCESS) goto out; // Push bitmap onto stack. - bstack->stack->push(bitmap_copy); + bstack->stack.push(bitmap_copy); out: if (rc != QV_SUCCESS) { hwloc_bitmap_free(bitmap_copy); @@ -131,13 +113,13 @@ int qvi_bind_pop( qvi_bind_stack_t *bstack ) { - hwloc_bitmap_free(bstack->stack->top()); - bstack->stack->pop(); + hwloc_bitmap_free(bstack->stack.top()); + bstack->stack.pop(); return qvi_rmi_task_set_cpubind_from_cpuset( bstack->rmi, qvi_task_task_id(bstack->task), - bstack->stack->top() + bstack->stack.top() ); } diff --git a/src/qvi-task.cc b/src/qvi-task.cc index 9ecab736..3401ccd2 100644 --- a/src/qvi-task.cc +++ b/src/qvi-task.cc @@ -16,45 +16,36 @@ #include "qvi-common.h" // IWYU pragma: keep #include "qvi-task.h" +#include "qvi-utils.h" static const int qvi_task_id_invalid = -1; struct qvi_task_s { + int qvim_rc = QV_SUCCESS; /** Task ID */ qvi_task_id_t task_id = {}; /** Global task ID */ int64_t gid = qvi_task_id_invalid; /** Node-local task ID */ int lid = qvi_task_id_invalid; + /** Constructor */ + qvi_task_s(void) = default; + /** Destructor */ + ~qvi_task_s(void) = default; }; int qvi_task_new( qvi_task_t **task ) { - int rc = QV_SUCCESS; - - qvi_task_t *itask = qvi_new qvi_task_t(); - if (!itask) { - rc = QV_ERR_OOR; - } - if (rc != QV_SUCCESS) { - qvi_task_free(&itask); - } - *task = itask; - return rc; + return qvi_new_rc(task); } void qvi_task_free( qvi_task_t **task ) { - if (!task) return; - qvi_task_t *itask = *task; - if (!itask) goto out; - delete itask; -out: - *task = nullptr; + qvi_delete(task); } int