Skip to content

Commit

Permalink
Begin using qvi_new_rc() and qvi_delete(). (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Mar 14, 2024
1 parent c8b5d8e commit 5c1d82a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 83 deletions.
49 changes: 21 additions & 28 deletions src/qvi-bbuff.cc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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. */
Expand All @@ -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 *
Expand Down
58 changes: 20 additions & 38 deletions src/qvi-bind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<hwloc_cpuset_t>;

// 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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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()
);
}

Expand Down
25 changes: 8 additions & 17 deletions src/qvi-task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c1d82a

Please sign in to comment.